Java EE 8: Manipulating JsonObjects with JsonPatch

JSON-P (JSR-374) from Java EE 8 comes with JSON Patch support, which can be used for manipulation (patching) of JsonObject instances (see also Java EE 8 and JSON-P Simplify System Testing with JSON Patch):

public void patch() {
    JsonObject sub = Json.createObjectBuilder().
            add("name", "EE4J").

    JsonObject initial = Json.createObjectBuilder().
            add("fact", "Java EE is nice").
            add("myth", "Java EE is heavyweight").
            add("future", sub).

    JsonPatch patch = Json.createPatchBuilder().
            add("/version", "8").
            replace("/fact", "Java EE rocks").
            replace("/future/name", "Jakarta EE").

    JsonObject result = patch.apply(initial);
    System.out.println("result = " + result);


result = {"fact":"Java EE rocks","future":{"name":"Jakarta EE"},"version":"8"}

JSON-P comes as a single maven dependency:


See you at Java EE Workshops at MUC Airport, particularly at the Effective Java EE 8 workshop

NEW: Online Workhop Effective WebApps without Frameworks is also coming to: MUC Airport.

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: and newsletter:

A book about rethinking Java EE Patterns


Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments