I’m trying to normalize the JSON getting from GraphQL API and convert it to dataframe using json_normalize JSON
JavaScript
x
41
41
1
[{
2
"node": {
3
"organization": {
4
"company": "System"
5
},
6
"id": "15",
7
"ip": "10.6.11.110",
8
"name": "devce_name",
9
"deviceClass": {
10
"logicalName": "class OEM",
11
"class": "class",
12
"description": "OEM",
13
"deviceCategory": {
14
"name": "Unknown"
15
}
16
},
17
"asset": {
18
"location": "",
19
"make": "make"
20
},
21
"events": {
22
"edges": [
23
{
24
"node": {
25
"message": "Device message",
26
"severity": "3
27
}
28
},
29
{
30
"node": {
31
"message": "message",
32
"severity": "2",
33
}
34
}
35
]
36
}
37
}
38
},
39
40
]
41
This is the json_normalize using pandas I’m trying
JavaScript
1
6
1
nd = pd.json_normalize(
2
res,
3
record_path=["node", "events", "edges"],
4
meta= [["node", "organization", "company"], ["node", "name"], ["node", "ip"], ["node", "id"], ["node", "deviceClass"]]
5
)
6
If the meta inside size was 2 then is no error,
eg:- meta= [[“node”, “organization”], [“node”, “name”], [“node”, “ip”], [“node”, “id”], [“node”, “deviceClass”]]
but when I tried for more than 2 in the list then I getting below error.
eg: meta= [[“node”, “organization”, “company”], [“node”, “name”],[“node”, “id”], [“node”, “deviceClass”]]
KeyError: ‘company’ The above exception was the direct cause of the following exception: …. KeyError: “Try running with errors=’ignore’ as key ‘company’ is not always present”
How to add more than 3 fields inside the meta?
Thanks