Open
Description
String jsonPath = "max($.dataset[*].value)";
String json1 = "{\"dataset\": [{\"value\": 1}, {\"value\": 3}, {\"value\": 2}]}";
String json2 = "{\"dataset\": [{\"value\": 4}, {\"value\": 3}, {\"value\": 2}]}";
JsonPath compiledJsonPath = JsonPath.compile(jsonPath);
System.out.println(compiledJsonPath.read(json1).toString());
System.out.println(compiledJsonPath.read(json2).toString());
The first evaluation is successful but the second fails:
Exception in thread "main" com.jayway.jsonpath.JsonPathException: Aggregation function attempted to calculate value using empty array
at com.jayway.jsonpath.internal.function.numeric.AbstractAggregation.invoke(AbstractAggregation.java:59)
at com.jayway.jsonpath.internal.path.FunctionPathToken.evaluate(FunctionPathToken.java:41)
at com.jayway.jsonpath.internal.path.RootPathToken.evaluate(RootPathToken.java:66)
at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:99)
at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:107)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:179)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:393)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:377)
The issue affects 2.8.0 and 2.9.0 and it seems it was introduced with a60e96d.
There is a workaround to use max($.dataset..value)
json path instead but it is not really nice and cannot work if the field being aggregated exists at different levels in the input data. The [*]
notation should also work as it did in 2.7.0.
Metadata
Metadata
Assignees
Labels
No labels