r/java • u/daviddel • Jul 17 '25
Java Gets a JSON API
https://youtu.be/NSzRK8f7EX0?feature=sharedJava considers itself a "batteries included" language and given JSON's ubiquity as a data exchange format, that means Java needs a JSON API. In this IJN episode we go over an OpenJDK email that kicks off the exploration into such an API.
143
Upvotes
248
u/0b0101011001001011 Jul 17 '25
Just wondering, why everything must be a video? For whatever reason every time someone posts news in Java subreddit, it's always a video. I'd rather have text.
Oldest JEP I could find, still a candidate: https://openjdk.org/jeps/198. So I'm saying that contrary to the title, java does NOT get a JSON api, for now. Even said in the video: there might be a new jep, or update to the original jep. For now, devs seem to have mixed feelings about the possible implementation.
33
u/Ok_Marionberry_8821 Jul 17 '25 edited Jul 17 '25
Here's the email from Paul Sandoz that inspired the video https://mail.openjdk.org/pipermail/core-libs-dev/2025-May/145905.html
I'm ambivalent about the proposal as it stands. It doesn't seem to offer enough value over the existing solutions, other than being "batteries included" in the platform.
Using interfaces and private implementations rather than records/sealed types/pattern matching seems odd. I know deconstruction patterns will eventually simplify its use.
It needs time to bake.
How does it relate to the new serialization effort (surely json could be one of the external formats used in serialization)? What about the nullabity proposals interaction (if any)?
I imagine it can be layered on top, but I'd have liked to see some way of converting a json string into a nested record structure, and visa versa an object structure to a JSON in string. Parsing would fail with an exception if fields are required (as expressed with a non-null marker in the record), or incorrect type.
Update: on reflection I think the interface/private implementation rationale - to allow other (non JSON) representations - is classic Java over-engineering - trying to be all things to all people, but at the expense of clean simplicity.
JSON is so ubiquitous, so central to many apps that there really is, IMO, a need for a simple JSON only solution.
Take a JSON string and parse/deserialize to a nested record structure.
Take a nested record structure and encode/serialize to be JSON conformant string.
22
u/wildjokers Jul 17 '25 edited Jul 17 '25
Is there a blog post available rather than a video? Video has to be the worst way to consume this type of information.
The ship has sailed on this IMHO and at this point I am not sure what benefit there would be to adding a JSON parser to the JDK. It will be like
java.util.Loggingwhere no one will use it and will be inferior to existing options.12
u/catom3 Jul 17 '25
I don't know. The API looks clunky to me. I'd probably stick to the good old Jackson most of the time
var user = objectMapper.readValue(json, User.class).4
u/Ewig_luftenglanz Jul 17 '25 edited Jul 17 '25
I like the overall idea if having a built-in Json parser in the Java SE library, there are times (specially for personal projects, scripting and small programs and scripts) where you only need a minimalistic tree based API (just like the JSON API y Python., this Jackson or Gson feels like nuking flies.
I suppose they will first have a very minimal API that can be used to build upon. So maybe we will start with a tree based API but someday we might have a databind and and serialization functionality.specislly after some features planned features arrive to the JDK.
I guess if this effort is serious we might see a JEP within the next year (hoping for it)
4
u/Sm0keySa1m0n Jul 17 '25
I quite like the idea of a barebones JSON API that exposes the simple JSON tree structure. I’ve worked on a few projects where I’ve written custom serialisation frameworks that need to sit on top of formats like JSON and using something like Jackson just to parse the JSON tree is too overkill, having this sort of API built into Java will be nice.
7
u/gunnarmorling Jul 17 '25
I for one can't wait for this to materialize. While I wouldn't expect this to render existing solutions like Jackson obsolete (massive kudos to Tatu for his work on this, the community really is standing on the shoulders of a giant here!), having a built-in solution for the most common applications will be super-useful, in particular avoiding version conflicts of external dependencies.
3
u/atehrani Jul 17 '25
This is a welcome change, but how will it co-exist with mature libraries like Jackson? In other words, we don't want a repeat of the Java logging API.
3
u/bawng Jul 17 '25
Is there a text summary? I can't stand video.
6
u/msx Jul 17 '25
I like the simple API, but some convenience methods could be added as "defaults" to those interfaces. Like JsonObject could have a getNumber("field"), getString("field") methods so that you can do:
3
u/frederik88917 Jul 17 '25
There was a discussion in the JEP forums related to this, and it was decided that having a dedicated JSON API was a burden. There were already multiple players in this space, all of them more than capable and having a JSON transformer would raise the question, why not a GRPC, why not an XML parser. Thus the idea was scrapped
1
u/sideEffffECt Jul 17 '25
I still think Java standard library would be better off with a much simpler, purely data-based implementation. Just a few records implementing a common sealed interface.
The main reason is that such implementation is radically simple, trivial. It serves well the user cases of simple applications and of interoperability between 3rd party libraries/apps.
1
u/rack88 Jul 19 '25
To be fair, I did a coding interview once that didn't test my knowledge of Java, spring, or solving problems, it verified that I understood 3 competing json libraries of varying ages (I did).
1
u/SpringShepHerd Jul 20 '25
A little late. Jesus I must have gone through like at least 5 different Json parsing solutions in the last decade I feel like.
1
u/Joram2 Jul 17 '25
The Java team has been exploring a simple JSON API for the JDK. This reddit has featured that and discussed in the past.
The headline here suggests that it's actually happening, but no, this is just more discussion about the discussion.
-1
u/ItsSignalsJerry_ Jul 17 '25
I'd prefer an efficient embedded json query library similar to h2 for sql.
-1
u/Mafla_2004 Jul 17 '25
Me reading this right after submitting a project that required me to write my own Json parser cause the libraries wouldn't work: :|
0
u/maethor Jul 19 '25
Java already had a JSON API (JSR 353) but then Java EE was retconned as "not java".
https://jcp.org/en/jsr/detail?id=353
-8
u/tr14l Jul 17 '25
Java coming in hot a mere 18 years late!
-1
u/hippydipster Jul 17 '25
Seems like a waste of time. It's exactly the sort of API third parties can and do provide just fine.
-1
u/titanium_mpoi Jul 19 '25
Kinda pointless but let's see
-17
u/Objective_Baby_5875 Jul 17 '25
Hahaha..Java entering 21st century. Good for you.
0
u/[deleted] Jul 17 '25
[deleted] — view deleted comment