Sunday, 21 May 2023

how do you extract data from nested json file and create a data frame in python

I have this nested json data:

    {
  "result": [
    {
    "deviceid": 33,
    "devicename": "server101",
    "objectName": "CPU",
    "data": [
    {
      "value":0.59,
      "rvalue":null
    },
    {
      "value":90,
      "rvalue":null
    },
    {
      "value": 85,
      "rvalue":null
    }
          ]
  },
  {
  "deviceid": 30,
    "devicename": "server10",
    "objectName": "CPU",
    "data": [
    {
      "value":0.30,
      "rvalue":null
    },
    {
      "value":60,
      "rvalue":null
    },
    {
      "value": 79,
      "rvalue":null
    }
    ]
  },
  {
  "deviceid": 0,
    "devicename": "server300",
    "objectName": "CPU",
    "data": [
    {
      "value":0.10,
      "rvalue":null
    },
    {
      "value":0.20,
      "rvalue":null
    },
    {
      "value": 0.25,
      "rvalue:":null
    }]
  }
  ],
  "timeRanges": [
    {
      "name":"1st Month",
      "startTime":1680000000,
      "endTime": 1689000000
    },
    {
      "name":"2nd Month",
      "startTime": 1680000000,
      "endTime": 1689000000
    },
    {
      "name":"3rd Month",
      "startTime": 1680000000,
      "endTime": 1689000000 
    }
  ]
}

I need to extract data from this json and append to a data frame.

The output should be like this:

deviceid deviceName objectName 1stMonth 2ndMonth 3rdMonth. startTime. endTime
33      server101  CPU      0.59     90      85       1680000000  1689000000
30      server10   CPU      0.30     60      79      1680000000  1689000000
0       server300  CPU      0.10     0.20    0.25     1680000000  1689000000

I am very new to this and would appreciate any guidance.



from how do you extract data from nested json file and create a data frame in python

No comments:

Post a Comment