-1

Suppose I have a json like this { "city" :[ "Bangalore", "Delhi", "Chennai", "Bangalore" ] } Now I want to make a make a json path query to check if bangalore is occuring twice or not so to check that I want to extract no of times Bangalore is coming in array so how can we build the jsonpath expression?

agrawal1084
  • 129
  • 2
  • 11
  • Did my answer work for you? If it did please accept it as the right answer, otherwise please add a comment why not. – Bartios Oct 09 '18 at 09:31

1 Answers1

1

I'm not sure I completely understand what you are asking but I guess you are using jayway's jsonpath library in java. In that case you can probably use this:

int amountOfBangalore = JsonPath.parse(json).read("$.city.[?(@ == \"Bangalore\")]").length();

Where you construct a list filled with each instance of 'bangalore' in the text and then call length() on that.

Bartios
  • 99
  • 5