简体   繁体   中英

Facing a issue in json file using Python

I am new to Python and Json. I am trying to convert xml content into json using python.

i have an xml file with as below:

<pins>
        <pin name="PA3">
            <pinNumber package="QFN64" value="1"/>
            <pinAlias alias="PA3" module="GPIO"/>
.....

I am able to generate json file using xmltodict in python created as shown below:

{
  "device": {
    "pins": {
      "pin": [
        {
          "pinAlias": [
            {
              "alias": "PA3", 
              "module": "GPIO"
            }, ......

But i need to generate the json file as:

{
  "device": {
    "pins": [
        {
          "pinAlias": [
            {
              "alias": "PA3", 
              "module": "GPIO"
            },.... 

Can anyone help me in achieving this?

Assuming your data structure is named d :

d['pins'] = d['pins']['pin']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM