hoverfly icon indicating copy to clipboard operation
hoverfly copied to clipboard

Filtering root level field with JsonPath Expression

Open ghost opened this issue 8 years ago • 9 comments

Partial matching of request using jsonPath match is not working when I am trying to match the root element. For example: "body":{
"jsonMatch":"{\t"itemId": \”<VALUE_A>",\t"stockNumber": "AA323IK",\t"count": "324"}" } As per TommySitu Tommy Situ @tommysitu Jun 22 10:26 @subham1112, the standard JSONPath expression to achieve what you need is "$[?(@.itemId == 123456)]” Unfortunatly the JSONPath go library we are using doesn’t work properly if the JSON node in the query is a root attibute.

Please help.

ghost avatar Jul 11 '17 22:07 ghost

Firstly, jsonPathMatch doesn't work probably if the JSON node in the query is a root attribute. This is a known issue. Another thing is that your example is using jsonMatch, not jsonPathMatch

tommysitu avatar Jul 12 '17 08:07 tommysitu

Do we have any plan to fix this known issue?

pradeepsingh1234 avatar Jul 12 '17 12:07 pradeepsingh1234

Any news on this ?

maxtepkeev avatar Jul 27 '17 14:07 maxtepkeev

Quickly looking at this, this looks like a duplicate issue of #636.

benjih avatar Jul 28 '17 13:07 benjih

I don't think the Go JsonPath library that hoverfly uses (https://github.com/NodePrime/jsonpath) supports root level filtering, for example: https://stackoverflow.com/questions/25031187/jsonpath-selecting-root-level-field-if-satisfies-a-condition

It could be a problem for some users, and I will also raise this issue with that project.

tommysitu avatar Jul 28 '17 17:07 tommysitu

Thanks for the quick reply.

The https://github.com/NodePrime/jsonpath project looks abandoned to me, so I don't think that raising an issue with that project will help.

maxtepkeev avatar Jul 31 '17 08:07 maxtepkeev

Have you got any better suggestions @maxtepkeev ?

JohnFDavenport avatar Jul 31 '17 08:07 JohnFDavenport

At least 2 come to mind:

  1. Try to find another active project that implements jsonpath or if there's none
  2. Make a fork of the NodePrime/jsonpath, fix the bug there, make PR which will hopefully be merged someday. Until it's not merged vendor this fork.

maxtepkeev avatar Jul 31 '17 12:07 maxtepkeev

We have tried several jsonpath libraries for Golang and none of them does all the jsonpath magics. Also NodePrime/jsonpath is deprecated, hoverfly is now using this jsonpath package: https://github.com/kubernetes/client-go/blob/master/util/jsonpath

There will be a workaround once the matcher chaining feature is implemeted: https://github.com/SpectoLabs/hoverfly/issues/761

tommysitu avatar Nov 29 '18 11:11 tommysitu