12/5/16
http://stackoverflow.com/questions/2835559/parsing-values-from-a-json-file-in-python
http://stackoverflow.com/questions/2835559/parsing-values-from-a-json-file-in-python
[]
are for lists, {}
are for dictionaries.
Here's how your JSON file should look:
{
"maps": [
{
"id": "blabla",
"iscategorical": "0"
},
{
"id": "blabla",
"iscategorical": "0"
}
],
"masks": {
"id": "valore"
},
"om_points": "value",
"parameters": {
"id": "valore"
}
}
Then you can use your code:
import json
from pprint import pprint
with open('data.json') as data_file:
data = json.load(data_file)
pprint(data)
- With data, you can now also find values like so:
data["maps"][0]["id"] ...... here [0] because maps has values in [..]. If [0] not used it will throw string - int error.
data["masks"]["id"]
data["om_points"]
- How I can get the number of elements in node of JSON data?
Convert it in dict.
|
How to handle json key errors in json??
ReplyDeleteHow to identify, which key failed in python key error??
ReplyDelete
Deletehttps://stackoverflow.com/questions/23139024/which-key-failed-in-python-keyerror