-2

I am working on a project which outputs a JSON file with certain characteristics, example below. How can I extract the values that are assigned to the "top", "left", "width" and "height" and assign these values to separate variables within Python3.7.

Detection result:
detection_02
JSON:
 [
  {
    "faceId": "4c1cb007-ed71-42d4-b2af-7abc3e82210e",
    "faceRectangle": {
      "top": 76,
      "left": 446,
      "width": 226,
      "height": 284
    },
    "faceAttributes": null,
    "faceLandmarks": null
  }
]
AxiomOfTruth
  • 315
  • 1
  • 2
  • 10

1 Answers1

-1
import json

json_data = json.loads(data_to_load)

top = json_data[0]['faceRectangle']['top']
left = json_data[0]['faceRectangle']['left']
width = json_data[0]['faceRectangle']['width']
height = json_data[0]['faceRectangle']['height']
Just for fun
  • 4,102
  • 1
  • 5
  • 11