Convert string to JSON using Python


I'm a little bit confused with JSON in Python. To me, it seems like a dictionary, and for that reason I'm trying to do that:

        "title": "example glossary",
            "title": "S",
                    "ID": "SGML",
                    "SortAs": "SGML",
                    "GlossTerm": "Standard Generalized Markup Language",
                    "Acronym": "SGML",
                    "Abbrev": "ISO 8879:1986",
                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
                        "GlossSeeAlso": ["GML", "XML"]
                    "GlossSee": "markup"

But when I do print dict(json), it gives an error.

How can I transform this string into a structure and then call json["title"] to obtain "example glossary"?

5/24/2019 5:03:37 PM

Accepted Answer


import json

d = json.loads(j)
print d['glossary']['title']
7/24/2018 8:28:23 AM

When I started using json, I was confused and unable to figure it out for some time, but finally I got what I wanted
Here is the simple solution

import json
m = {'id': 2, 'name': 'hussain'}
n = json.dumps(m)
o = json.loads(n)
print o['id'], o['name']    

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow