How to remove all the Keys under all elements that have a value 'NONE', so in this example busCode, effectivedate and col1. Sample Json and the python code that I tried are pasted here
{
"colo": {
"TrBus":{
"trade": "Test999",
"busCode": "NONE",
"Trtype": "XXX",
"sortOrder": "78654",
"effectivedate": "NONE",
"expirationdate": "31-DEC-9999"
}
"TrCol":{
"Col1": "NONE",
"Col2": "Conf"
} }
}
I started off with this but doesn't work as expected
def constructJson(jsonstr):
jdata = json.load(jsonstr)
for key, value in jsonstr:
if value == 'NULL':
del key
return jdada
for key, value in jsonstr:should befor key, value in jdata:2.del keyshould bedel jdata[key]and 3. this is not recursive (meaning, it doesn't handle nested values)is not Nonewith!= "NONE"in the accepted answer and thenreturn remove_none(jdata)will work.