8000 Compiled JsonPath containing an aggregation function with [*] notation cannot be reused · Issue #1038 · json-path/JsonPath · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Compiled JsonPath containing an aggregation function with [*] notation cannot be reused #1038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
turcsanyip opened this issue May 5, 2025 · 0 comments

Comments

@turcsanyip
Copy link
        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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0