Answer the question
In order to leave comments, you need to log in
How to store paths for json file?
Good afternoon.
It is necessary to parse the json file, extract 130 fields from it.
The working version works without errors.
data_item = json.load(infile)
print(data_item['data']['variables']['startupProcessInfo']['iin'])
Answer the question
In order to leave comments, you need to log in
json = {'data':{'variables':{'startupProcessInfo':{'iin': 'first'}}, 'piid': 'second', 'executionState': 'third', 'creationTime': 'fourth'}}
path_arr = ["['data']['variables']['startupProcessInfo']['iin']",
"['data']['piid']",
"['data']['executionState']",
"['data']['creationTime']"]
for x in path_arr:
json_iter = json
path = x[2:-2].split("']['")
for p in path:
json_iter = json_iter[p]
print(json_iter)
========================== RESTART: E:/Python/1.py ==========================
first
second
third
fourth
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question