First time working with around with json files. I am using the following code to read through a json file in python:
l = []
with codecs.open('file.json', 'r', encoding='utf-8') as jsonfile:
for line in jsonfile:
data = json.loads(line)
l.append(data)
The list was made because when I was opening the file without the first and last line, every time I accessed data, only the last element was returned. For example,
with codecs.open('file.json', 'r', encoding='utf-8') as jsonfile:
for line in jsonfile:
data = json.loads(line)
data['item']
would only give the last item of the json dataset, instead of returning all the items in it. Now, there are more dictionaries(nested) inside the 'l' list making navigation through the dataset a bit complicated. Are there any recommendations for having to read through the file without lists where the file is not overwritten so that it stops giving me the last line for each dictionary key?