Parsing values from a JSON file in Python -
i have json in file:
{ "maps": [ { "id": "blabla", "iscategorical": "0" }, { "id": "blabla", "iscategorical": "0" } ], "masks": [ "id": "valore" ], "om_points": "value", "parameters": [ "id": "valore" ] }
i wrote script prints of json text:
json_data=open(file_directory).read() info = json.loads(json_data) pprint(data)
how can parse file , extract single values?
i think ignacio saying json file incorrect. have []
s when should have {}
s. []
s lists, {}
s dictionaries. here's how json file should (your json file wouldn't load me):
{"maps":[{"id":"blabla","iscategorical":"0"},{"id":"blabla","iscategorical":"0"}], "masks":{"id":"valore"}, "om_points":"value", "parameters":{"id":"valore"} }
then can utilize code:
import json pprint import pprint open('data.json') data_file: info = json.load(data_file) pprint(data)
with data, can find values in so:
data["maps"][0]["id"] data["masks"]["id"] data["om_points"]
try out , see if starts create sense.
python json parsing
No comments:
Post a Comment