hello,
I'm trying to parse a json file and print out each element along with some related infos such type and value.
I would like to do that in python and I found a nice support to quickly load the json file, instead I found a bit more difficult the information extraction.
Example, I have this json file:
{
"glossary": {
"title": "example glossary",
"GlossList": {
"GlossEntry": [
{
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossSee": "markup"
}
]
}
}
}
I can easly load with:
import json
..
json_file = json.load(file)
..
Now I would like to print out such infos:
"glossary" is an object, its dept level is 0
"title" is a string, its dept level is 1, its value is "example glossary"
"GlossList" is an object, its dept level is 1
"GlossEntry" is an array, its dept level is 3
....
....
The json lib easly allows to match a object->dict and array->list.
How could I loop through the json file easly and print such infos?
thanks
D