Apply JSONPath filter to field with space

你离开我真会死。 提交于 2019-12-23 16:34:41

问题


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.


回答1:


Extra brackets.

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


来源:https://stackoverflow.com/questions/34074569/apply-jsonpath-filter-to-field-with-space

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!