JamesNK / Newtonsoft.Json

Json.NET is a popular high-performance JSON framework for .NET
https://www.newtonsoft.com/json
MIT License
10.73k stars 3.25k forks source link

JsonPath evaluator does not accept complex expressions #2851

Open epaval-emc opened 1 year ago

epaval-emc commented 1 year ago

The following JsonPath expression, $[?(@.result_date === null && (@.realized > 0 || @.report_period == 'Q1'))] will fail with "Unexpected character while parsing path query: ("

It appears the paranthesis are reserved for ?() evaluator and not accepted in the expression anywhere. I was not able to find an escape character that will make this work. I verified the expression online at jsonpath.com and it works over there.

Source/destination JSON

[
  {
    "result_date": null,
    "realized": 4719.87,
    "report_period": "Q1"
  },
  {
    "result_date": null,
    "realized": 1559.87,
    "report_period": "Q2"
  },
  {
    "result_date": "2018-01-23",
    "realized": -474.51,
    "report_period": "Q1"
  },
  {
    "result_date": null,
    "realized": 3474.514,
    "report_period": "Q3"
  },
  {
    "result_date": null,
    "realized": 9781.615,
    "report_period": "Q4"
  }
]

Expected behavior

I expected SelectToken(jsonPath) for the above expression to return some array items.

Actual behavior

SelectToken just throws an error : "Unexpected character while parsing path query: ("

Steps to reproduce

// Your calls to Newtonsoft.Json here