0

I trying access to value Carrier by taking value from shipping_id. I testing queries at https://www.jsonquerytool.com/. If I type key by hand $.shipping_methods["11"] or $.shipping_methods.11I receive correct result ["Carrier"]. But I have problem with taking key value from shipping_id field. I was trying with many variations of this $.shipping_methods[$.shipping_id] but without success. It's possible with pure jsonPath?

{
   "shipping_id":"11",
   "shipping_methods":{
      "10":"Post",
      "11":"Carrier"
   }
}
jasufo
  • 33
  • 4

1 Answers1

0

Depending on the JSON-Path implementation/environment you are using this may or may not be possible. This is because the feature you are asking for is not of the proposed standard, though some libraries have features that enable queries like that, e.g. in JSONPath-Plus you could use @property and @parent (I had no success using @root) - but those are 'extensions':

$.shipping_methods[?(@property == @parent.shipping_id)]

You can test this online here.

The page you have linked is using JSPath under the hood, and I cannot see any of the required features mentioned in the readme. It would be simpler to drill down in a general programming language that hosts the JSON-Path engine but not sure if this is an option here.

wp78de
  • 18,207
  • 7
  • 43
  • 71