Skip to content

Conversation

@movabo
Copy link

@movabo movabo commented Dec 19, 2025

Based on #1015, this PR adds the possibility to add custom functions. It implements the separation of contexts as per this suggestion.

Therefore, a PathFunctionProvider replaces the PathFunctionFactory and is now part of the Configuration.

Example:

String json = "...";

Configuration conf = Configuration.defaultConfiguration().pathFunctionProvider(new DefaultPathFunctionProvider() {
    @Override
    public PathFunction newFunction(String name) throws InvalidPathException {
        if (name.equals("toUpperCase")) {
            return (currentPath, parent, model, ctx, parameters) -> ((String) model).toUpperCase();
        }
        
        // Fall back to default functions
        return super.newFunction(name);
    }
});

JsonPath.using(conf).parse(json).read("$.store.book[0].author.toUpperCase()").toString(); // NIGEL REES

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

Successfully merging this pull request may close these issues.

1 participant