Functions min(), max() or sum() with JSONPath



According to JsonPath on GitHub it shall be possible to access max(), min() or the sum() of an array but I don’t know how. I have the following example data:





































I would expect it to work like:


so I’m trying:


But that didn't do the job.

Can someone help me?


Your JSON data contains a set of records and you need to perform aggregation on these sets. The example code uses a sum operation, and similar way of handling is for both min and max. Yet JSONPath only supports aggregation on a simple set and enumeration before aggregation, but it does not support aggregation on a set of records.

You can use SPL, an open-source Java package, to do it if you want a simple and easy alternative. You just need a single line of code:




SPL offers JDBC driver to be invoked by Java. Just store the above SPL script as sum.splx and invoke it in a Java application as you call a stored procedure:


con= DriverManager.getConnection("jdbc:esproc:local://");

st = con.prepareCall("call sum()");

View SPL source code.