Convert string to JSON using Python
Posted
by
Luiz Fernando
on Stack Overflow
See other posts from Stack Overflow
or by Luiz Fernando
Published on 2010-12-24T19:48:19Z
Indexed on
2010/12/24
19:54 UTC
Read the original article
Hit count: 399
Hi,
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:
json = """{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"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"?
Thanks.
© Stack Overflow or respective owner