Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply JSONPath filter to field with space

I'm trying to use JSONPath (https://github.com/jayway/JsonPath) to search a document which has spaces in the field names:

{
  "model": {
    "Details": {
      "Nospace": "New today",
      "Random nonsense": "New today"
    }
  }
}

I'm testing using the evaluator at http://jsonpath.herokuapp.com/

This works:

$.model.Details[?(@.Nospace== 'New today')]

But this does not:

$.model.Details[?(@.'Random nonsense'== 'New today')]

This does but is missing the filter expression:

$.model.Details['Random nonsense']

So it seems it's possible to refer to fields with spaces, but I haven't found how to use them in a filter. Is it possible? I have tried many other combinations with no luck, and don't seem to find anything online about it either.

Thanks.

like image 382
woddle Avatar asked Oct 21 '25 14:10

woddle


1 Answers

Extra brackets.

$.model.Details[?(@['Random nonsense'] == 'New today')]
like image 129
woddle Avatar answered Oct 23 '25 04:10

woddle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!