SK07
7 years agoContributor
Groovy- count all nulls in an array
I want to print how many nulls, 1's and 2's seperately.
Json : {"prods": [{"Item":13,"rate":200, "Ids": []}, {"Item":13,"rate":200, "Ids": []},
{"Item":11,"rate": 100, "Ids": [ {"level": 1}]},
{"Item":13,"rate":200, "Ids": [ {"level": 1}]},
{"Item":12,"rate":200, "Ids": [ {"level": 2} ], [{"level": 2}, {"level": 2}]} ]}.
I tried and couldnt get the counts seperately.def jsonids = json.Ids
log.info jsonids
[[], [], [1], [1], [2, 2, 2]]
I want the results like below:
Level []: 2, Level 1: 2, Level 2: 3
Any help is appreciated.
Nulls: 2