I still remember the first time I had to grab a single value out of a JSON response and reached for Jackson to do it. Add the dependency, register the ObjectMapper, write a DTO for a payload I was going to look at exactly once, all to read one field. It felt like renting a moving truck to carry a suitcase.
That has been the story of JSON in Java for two decades now. Jackson, Gson, JSON-P, all excellent libraries, all doing far more than you need for the quick stuff. Meanwhile in Python you write json.loads(response.text)["forecast"][0]["temp"] and you are done. Java never had an answer for that. Until now, maybe.
What JEP 540 actually proposes
JEP 540 is called Simple JSON API (Incubator). It is an incubating module, so nothing here is locked in stone yet, but the shape of it is worth understanding early.
The idea is small on purpose. A Json class with a parse method that turns a JSON document into a tree of JsonValue instances. JsonValue is a sealed interface, and it has exactly six subtypes, matching the six things a JSON document can contain: JsonObject, JsonArray, JsonString, JsonNumber, JsonBoolean, and JsonNull.
Sealed means the compiler knows the full set of subtypes in advance. If you have followed modern Java pattern matching, this should feel familiar: sealed hierarchies are what make exhaustive switch expressions possible without a default branch you never wanted to write in the first place:
| |
No default clause, no “this should never happen” comment above a RuntimeException. The compiler already knows there is nowhere else to go.
Reading values, the honest way
Each subtype exposes conversions appropriate to what it actually is. JsonObject gives you asMap(), JsonArray gives you asList(), and the primitive types give you the usual asInt(), asString(), and friends.
Here is the part I like: if you call asInt() on something that turns out to be a JsonString, it doesn’t try to be clever and parse the string into a number for you. It throws a JsonValueException. No silent coercion, no “helpful” behavior that quietly hides a bug three services downstream.
I once spent three hours tracing a production discrepancy in a billing pipeline because an external library helpfully parsed a floating-point "amount": 100.50 into an integer 100 without a squeak, silently dropping the cents. JEP 540 refuses to play those games. If you call .asInt() on a number with a fractional part, or if you expect a number and get a string, the runtime blows up immediately. You get exactly the type you asked for, or you get told you were wrong to expect it.
Strictness by default: No duplicate keys
The strictness does not stop at data types. Under RFC 8259, member names within a JSON object should be unique, but many third-party parsers are forgiving: if an incoming object has duplicate keys, they quietly let the last value overwrite the first. That looseness is a notorious attack vector for JSON smuggling and parser-differential exploits between microservices.
JEP 540 takes a zero-tolerance stance: duplicate keys unconditionally throw a JsonParseException with the exact line number, column, and object path. If a producer emits ambiguous JSON, your parser fails fast rather than guessing.
A walkthrough: Tax assessment lookup
The JEP’s own example pulls average forecast temperatures out of a National Weather Service response. That is a decent demo, but let’s look at something closer to an enterprise backend.
Say you are calling out to a downstream revenue service that returns an income tax assessment notice, and all you want to do is grab the total liability and tally up the approved deduction credits:
| |
The source examples can be downloaded from my Github
To run this code, you need to add --add-modules jdk.incubator.json like this java --add-modules jdk.incubator.json TaxAssessmentDemo.java
Notice what is missing: no Jackson dependency in your pom.xml, no DTO records, no @JsonProperty annotations, and zero explicit downcasting. You do not have to call root.asObject().get(...) or get("deductions").asArray(). The JsonValue interface provides polymorphic .get(String) and .get(int) accessors directly. If you navigate into a path that does not exist, you get a clean JsonValueException pinpointing the exact property path where your expectations diverged from reality.
What it deliberately leaves out
This is not a Jackson replacement, and it was never trying to be one. There is no data binding, so no mapping straight into your own Java domain objects. There is no JSON5 support, no comments, and no trailing commas. There is no streaming parser for gigabyte-sized documents.
If you need full object graph deserialization or streaming event tokens, you are still reaching for Jackson, Gson, or Jakarta JSON Processing, and that is fine. JEP 540 exists for the other 80 percent of cases: the ones where you just need to inspect a response, grab a couple of fields, and move on with your day.
Generating and printing JSON: Two methods and a factory tree
Reading a JSON payload is only half the battle. If you are building an AI agent callback, generating a response for an HTTP probe, or assembling a configuration snippet on the fly, you need to construct a JSON tree in code and write it out.
Building a document uses factory methods across the sealed subtypes:
| |
Printing the document introduces a crucial distinction you will want to remember:
- Compact representation via
toString(): Calling.toString()on anyJsonValueproduces a single-line, whitespace-free string conforming strictly to RFC 8259. This is what you send across a socket or write into a high-throughput structured log. Note that.toString()is completely different from.asString():.asString()extracts the unescaped Java String value from aJsonStringnode and throws an exception on anything else, whereas.toString()serializes the node into valid JSON syntax. - Pretty-printed display via
Json.toDisplayString(value, indent): When you need formatted output for debugging, terminal tools, or config dumps, the staticJson.toDisplayString()method handles the formatting. You pass in the root node and your choice of indentation string (such as two spaces or a tab). It handles the linebreaks and nested indentation cleanly.
Both forms are guaranteed to be fully round-trippable. What you emit with either payload.toString() or Json.toDisplayString(payload, " ") will parse right back into an identical JsonValue tree via Json.parse().
The pushback (and why ceremony beats magic in AI workflows)
Not everyone is thrilled with the ergonomics. Over on Hacker News, one of the more common complaints is that building a JsonArray out of plain Java values takes more ceremony than people expected:
| |
Every value must be explicitly wrapped before it goes in. There is no automatic reflection or implicit conversion from a List<String> to a JsonArray of JsonString. It is a fair criticism for quick scripting, and this might get sanded down as the incubator matures.
If you have spent any time wiring up tool calling for LLMs in Spring AI or LangChain4j, though, you will recognize why this design makes sense. Implicit magic is the enemy of reliable agents. When every node in the tree is explicitly typed, you never have to guess how a serializer will handle a nested structure or whether an empty optional turns into a missing key or a literal null. In agentic architectures, a little typing ceremony at the keyboard prevents massive hallucinations at runtime.
Why not records and sealed interfaces all the way down?
If you have followed data-oriented programming in Java, you will have the same initial reaction I did: why isn’t this just a sealed interface with public record implementations? That is the textbook pattern for algebraic data types.
Turns out the JDK team considered it and deliberately passed. Nicolai Parlog covered this well on Inside Java Newscast: records expose their components as an immutable part of the public API contract. For something as foundational as a JDK-shipped JSON type, the team wanted room to evolve the underlying memory layout and optimizations later without breaking anyone. So instead you get sealed interfaces with hidden implementations: JsonValue at the top, with accessor methods instead of public record components. Less pure from a theoretical standpoint, but far more defensible for a standard library class that will outlive most of our codebases.
Where will you actually use this?
Once JEP 540 lands, you will likely reach for it in three common scenarios:
- Single-file source code programs (JEP 330): When writing quick infrastructure scripts, Kubernetes sidecar initializers, or database migration checks in pure Java, you can now parse JSON payloads without setting up a Maven build or pulling in a dependency tree.
- AI agent tool callbacks: When an LLM executes a tool call and hands you a JSON string of arguments, you often only need two or three parameters. JEP 540 lets you slice those arguments out directly with zero framework overhead.
- Lightweight configuration files: The JDK itself plans to use this to replace clumsy, sequentially numbered
.propertiesfiles with structured JSON. It is equally handy for your own microservice CLI flags and configuration files.
Where things stand
JEP 540 is an incubator module in JDK 28 (jdk.incubator.json). Because it is an incubator feature, you need to enable it explicitly at compile time and runtime:
| |
You can also experiment with it interactively in jshell:
| |
| |
Incubator modules exist specifically to gather feedback before APIs get cast in concrete. If you have strong thoughts on the wrapping ceremony or navigation ergonomics, now is the time to try it on early-access JDK 28 builds and send your feedback to the OpenJDK mailing lists.
The verdict
To be honest, it is too early to tell. As mentioned, it is an incubator API. Experience has shown, than these can take several rounds of changes.
I would not be surprised if this API won’t be final until the Java 33. Yup, that is not the coming LTS version, but the one after. I can see the value of having native JSON support in the JDK, even in this rudimentary form.
In my opinion, this is another move to make Java more user friendly to people new to the language.
We have simplified semantics, like the main methods used in our examples.
We even don’t need an outer class anymore now that we have unnamed classes.
We can import modules.
Being able to use JSON without any dependencies is the next step to lure data scientists away from Python and into the Java realm.
And for Java, that can only be a good move.
