Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create json from python dict

I try to create a peace of JSON from a python dict. Unfortunately I am not able to get the correct format yet. I need a array in my json object ‘types’. How can I fix this?

My code:

import json
association_item = {}
association_item['types']={}
association_item['types']['associationCategory'] = 'A'
association_item['types']['associationTypeId'] = '4'

My dict:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{'types': {'associationCategory': 'A', 'associationTypeId': '4'}}

My JSON:

{
    "types": {
        "associationCategory": "A",
        "associationTypeId": "4"
    }
}

What i want:

{
    "types": [{
        "associationCategory": "A",
        "associationTypeId": "4"
    }]
}

>Solution :

You need to add it correctly, like

association_item['types'] = 
    [ { 'associationCategory': 'A',
        'associationTypeId': '4' } ]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading