I have very large json I want to extract sum of data from it using jq.
I am trying every possible way but I think I am missing something here..
My Json subset:
{"main":
{"0": {"x": {"a":1}, "y": {"number of un-used":{"count":2} , "z":2}},
"1": {"x": {"a":1}, "y": {"number of un-used":{"count":3} , "z":2}},
"2": {"x": {"a":1}, "y": {"number of un-used":{"count":4} , "z":2}},
"3": {"x": {"a":1}, "y": {"no un-used":{"z":3} , "z":2}},
"4": {"x": {"a":1}, "y": {"no un-used":{"z":3} , "z":2}}},
"no-main":
{"0": {"x": {"a":1}, "y": {"number of un-used":{"count":2} , "z":2}},
"1": {"x": {"a":1}, "y": {"number of un-used":{"count":3} , "z":2}},
"2": {"x": {"a":1}, "y": {"number of un-used":{"count":4} , "z":2}},
"3": {"x": {"a":1}, "y": {"no un-used":{"z":3} , "z":2}},
"4": {"x": {"a":1}, "y": {"no un-used":{"z":3} , "z":2}}}}
I want the sum of "count" - "number of un-used" that is under "y".
My most successful one is:
cat json | jq '.[] | .[].y | .["number of un-used"] | .count'
But the results contains a lot of "null" because "number of un-used" is not in all of "y" dicts..
Is it solvable?