[Solved] Convert from Dict to JSON in Python


Python lists use commas, not colons:

json_dict = {'type': str("id"),
            'entries': [['a', "91"],  # note the comma after 'a', not a colon
                        ['b', "65"],
                        ['c', "26"],
                        ['d', "25"]]}

With commas, this is now valid Python syntax, producing a data structure that can be serialised to JSON:

>>> json_dict = {'type': str("id"),
...             'entries': [['a', "91"],
...                         ['b', "65"],
...                         ['c', "26"],
...                         ['d', "25"]]}
>>> import json
>>> json.dumps(json_dict)
'{"type": "id", "entries": [["a", "91"], ["b", "65"], ["c", "26"], ["d", "25"]]}'

1

solved Convert from Dict to JSON in Python