I am reading JSON file line by line. Few lines contain JSON objects while other contains JSON array. I am using json.loads(line) function to get JSON from each line.
def read_json_file(file_name):
json_file = []
with open(file_name) as f:
for line in f:
json_file.append((line))
json_array = []
for obj in json_file:
try:
json_array.append(json.loads(obj))
except ValueError:
print("data was not valid JSON")
return json_array
Is there any way that I can find out that object I am reading is JSON Object or JSON array? I want to save all the result in json_array.
I will be thankful to you if anyone can help me.