Is there a clever way to check if any array in a JSON element is not empty? Here is example data:
{
a = []
b = []
c = [1,2,3]
}
You can use any(), returning True if any of the values in the JSON object are truthy:
data = {
'a': [],
'b': [],
'c': [1,2,3]
}
result = any(item for item in data.values())
print(result)
This outputs:
True
if not somethingor more explicitlyif len(something) == 0or perhaps usefilter()while iterating, but this is not valid JSONjson), the data structure that you have is just a nested data structure of perfectly ordinary Pythondicts andlists, that you can and should process exactly the same way that you would if you had gotten that data in any other way.