json-path / JsonPath

Java JsonPath implementation
Apache License 2.0
8.78k stars 1.63k forks source link

concat is not working when comma (,) #872

Open snr-lab opened 1 year ago

snr-lab commented 1 year ago

Hi, When we are trying to concat with a comma the character is getting ignored. For example, my JSON data is { min: 5, max: 10, avg: 7 } and json-path is concat($.min, ",", $.max) The expected result is "5,10" but the actual result is "510"

yashbalija1 commented 1 year ago

You can modify the JSONPath expression to include a space before and after the comma:

concat($.min, " , ", $.max)

(OR)

concat($.min + " , " + $.max)

snr-lab commented 1 year ago

@yashbalija1 The extra space might create unwanted parsing issues in some scenarios. Apart from that, in my application the JSONPath is user-defined. So there is a high chance of oversight it even though we have quite good documentation.

yashbalija1 commented 1 year ago

@snr-lab you can use join([$.min, $.max], ",") this will give you the output as "5,10"

I think this should solve your issue.

snr-lab commented 1 year ago

@yashbalija1 I don't think there is any json function in jsonpath. Here is the documentation. https://github.com/json-path/JsonPath

yashbalija1 commented 1 year ago

yeah, there is no such function @snr-lab You can try this -> concat($.min, ",", $.max)

You can also use a scripting engine like JavaScript inside the JSONPath to achieve this. For example, you can use $.min + ',' + $.max inside the script function of the JSONPath to get the same result.

probably this might work