Newtonsoft.Json icon indicating copy to clipboard operation
Newtonsoft.Json copied to clipboard

jsonpath arithmetic operators support

Open NamanGajjar26 opened this issue 8 months ago • 1 comments

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

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

NamanGajjar26 avatar Oct 20 '23 05:10 NamanGajjar26

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.

elgonzo avatar Oct 20 '23 11:10 elgonzo