JSON output question, getting a list when there is only one element for structure

25 views
Skip to first unread message

Zeik

unread,
Dec 7, 2024, 8:40:20 PM12/7/24
to Bots Open Source EDI Translator
Hi All,

Trying to see if I am defining the structure wrong or if I need to do postprocessing to remove these [ ] when there is only 1 element in a record from my JSON file.  The below structure

structure = [
       
    {ID:'HEA',MIN:1,MAX:1,
    QUERIES:{
'frompartner': get_frompartner,
        'topartner':    get_topartner,
        },
    LEVEL:[
    {ID:"from_partner",MIN:1,MAX:1},
    ]},
    ]

is producing this

{
    "HEA": {
        "po_date": "10/23/2024",
        "from_partner": [
            {
                "city": "TESTCITY",
                "name": "TEST",
            }
        ]
    }
}

even though from_partner is only MIN/MAX of 1, it puts it in a list [ ]. 

Would like it to just look like this

{
    "HEA": {
        "po_date": "10/23/2024",
        "from_partner":
         {
                "city": "TESTCITY",
                "name": "TEST",
         }
    }
}

Is there a way to stop this?
Can I have just multiple roots or there has to be only one, since HEA seems to place things in { } only and not a list [ ]?

Thanks

Reply all
Reply to author
Forward
0 new messages