I'm trying to write a script transform that will take the JSON below and delete any leaf nodes with {label: null}
.
[
{
"icon": {
"path": "XXX",
"style": {},
"color": ""
},
"expanded": true,
"label": "XXX",
"data": {
"EqType": XXX,
"EqEnabled": true,
"EqName": "XXX",
"EqPath": "XXX",
"EqID": 1
},
"items": [
{
"icon": {
"path": "XXX/XXX",
"style": {},
"color": ""
},
"expanded": true,
"label": "XXX",
"data": {
"EqType": "XXX",
"EqEnabled": true,
"EqName": "XXX",
"EqPath": "XXX/XXX",
"EqID": 1
},
"items": [
{
"icon": {
"path": "XXX/XXX",
"style": {},
"color": "var(--error)"
},
"expanded": false,
"label": "QA Test Area",
"data": {
"EqType": "XXX",
"EqEnabled": false,
"EqName": "QA Test Area",
"EqPath": "XXX/XXX/XXX",
"EqID": 11
},
"items": [
{
"icon": {
"path": "material/block",
"style": {},
"color": "var(--error)"
},
"expanded": false,
"label": null,
"data": {
"EqType": "XXX",
"EqEnabled": null,
"EqName": null,
"EqPath": null,
"EqID": null
},
"items": []
}
]
}
]
}
]
}
]
However, I have not been able to figure out a way to write a Python conditional that checks if label: null
. This is what I attempted to do in the if statement below:
def transform(self, value, quality, timestamp):
for enterprise in value:
for site in enterprise["items"]:
for area in site["items"]:
for line in area["items"]:
if line["label"] == None:
del line
If someone could tell me how to check if a perspective property is null in Python, that would be very helpful.