This is my python code for parsing a JSON file.
import os
import argparse
import json
import datetime
ResultsJson = "sample.json"
try:
with open(ResultsJson, 'r') as j:
jsonbuffer = json.load(j)
result_data = json.loads(jsonbuffer)
print("Just after loading json")
except Exception as e:
print(e, exc_info=True)
I get an error like in the snapshot attached below.

I'm also attaching the JSON file "sample.json" that I'm using here. sample.json
{
"idx": 1,
"timestamp": 1562781093.1182132,
"machine_id": "tool_2",
"part_id": "af71ce94-e9b2-47c0-ab47-a82600616b6d",
"image_id": "14cfb9e9-1f38-4126-821b-284d7584b739",
"cam_sn": "camera-serial-number",
"defects": [
{
"type": 0,
"tl": [169, 776],
"br": [207, 799]
},
{
"type": 0,
"tl": [404, 224],
"br": [475, 228]
},
{
"type": 1,
"tl": [81, 765],
"br": [130, 782]
}
],
"display_info": [
{
"info": "DEFECT DETECTED",
"priority": 2
}
]
}
Not sure what I missed here. I'm very new to Python (Coming from C++ background). Please be easy on me if I've missed something basic.
json.load(j)already loads your json and transforms it to a python dictionary. When you do json.loads() it pretty much means json.load_string (as opposed to loading from file) so it expects a string but receives a dictionary. If you want to first read the file to a string you should use something liketextstring=f.read()or smtg like that.