wanglingsong / JsonSurfer

A streaming JsonPath processor in Java
MIT License
292 stars 55 forks source link

JSON transformation #61

Closed Mihailoff closed 2 years ago

Mihailoff commented 4 years ago

Hello, is it possible to use this library for JSON transformation?

I'd imagine returning value can be a convenient way to achieve this.

SurfingConfiguration config = surfer.configBuilder()
                .bind("$.store.book[*]", new JsonPathListener() {
                    @Override
                    public void onValue(Object value, ParsingContext context) {
                        return "new value";
                    }
                })
                .build(); 
wanglingsong commented 4 years ago

Yes. You can do anything in the listener to achieve transformation. However it is only a parsing library, JsonSurfer provide no particular feature for JSON transformation.

But you can have a look at this example in which JsonSurfer create Iterator from JSON and you can do transformation with less code: https://github.com/jsurfer/JsonSurfer#java-8-streams-api-support