I've a face detection code. What I want is to store metadata in json files in specific order. Basically I want to write how many faces exists in an image and the location of images. My code is the following:
data =[]
data.append({'number_of_faces':len(faces)})
nested_data = []
for (x,y,w,h) in faces:
nested_data.append({'face_x': x, 'face_y': y, 'face_h': h, 'face_w': w})
data.append(nested_data)
with open(json_path+folder+'/'+file_name, "w") as outfile:
json.dump(data, outfile)
The output is, for example:
[
{
"number_of_faces": 1
},
[
{
"face_h": 38,
"face_w": 38,
"face_x": 74,
"face_y": 45
}
]
]
However I want to create a nested json. Thus I want after number_of_faces object to have nested all face_location inside number_of_faces {}. How is it possible to do so?
jsonlibrary will just serialize the structure you pass to it.