JamesNK / Newtonsoft.Json

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

jsonpath arithmetic operators support #2909

Open NamanGajjar26 opened 10 months ago

NamanGajjar26 commented 10 months ago

"$.order[ ].Product[ ].price" "$.order[ ].Product[ * ].qut"

json path in multiply two field like upper example any solution for this

elgonzo commented 10 months ago

I am just a user of Newtonsoft.Json (like yourself) and not associated with the project nor its author/maintainer.

any solution for this

No, not with the JsonPath support as provided by Newtonsoft.Json as far as i know. You either have to do the arithmetic operations in code after obtaining the json elements of interest, or switch to an alternate json library/processor that supports arithmetic operations in JsonPath expressions.

A possible alternative might perhaps be json-everything -- in particular its JsonPath.Net package, which according to its documentation supports arithmetic operations. Note that json-everything is dependent on System.Text.Json. Also note that i have no noteworthy experience with json-everything, so i am not really able to give advice or opinions about it (and not withstanding the fact that this here is the issue tracker of Newtonsoft.Json and not a json-everything discussion forum). If json-everything isn't suitable for you, i am afraid you will have to seek out an alternative yourself...

P.S.: Keep in mind that arithmetic operations are not defined by the JsonPath specification (https://www.ietf.org/archive/id/draft-ietf-jsonpath-base-21.txt). Therefore, arithmetic operations constitute non-standard extensions of the JsonPath expression syntax. In other words, do not expect nor assume a common and well-defined way of how arithmetic operations would be realized across different JsonPath parser implementations.