0

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?

  • 1
    This question has been asked and answered before. Please see if solves your problem first, then update your question to point out the differences if it does not. Cheers! – drkstr101 May 23 '20 at 22:49
  • 2
    Does this answer your question? [How to dump a dict to a json file?](https://stackoverflow.com/questions/17043860/how-to-dump-a-dict-to-a-json-file) – Ronen Teva May 24 '20 at 11:28

1 Answers1

0

Assuming your data structure is named d:

d['pins'] = d['pins']['pin']
Błotosmętek
  • 12,717
  • 19
  • 29