r/java
•
u/loicmathieu
•
Jul 23 '26
•
1
JEP 540: Simple JSON API (Incubator)
https://openjdk.org/jeps/540
79
Upvotes
View all comments
Show parent comment
3
u/s888marks Jul 27 '26
It's kind of buried near the end, but the JEP text says,
The parsing/extraction parts of the API might seem fairly complete, but support for generating JSON docs seems fairly weak and there's essentially no support for transforming a JSON doc. Thus it seems reasonable to incubate while we explore these areas. Also, see below.
Tabs instead of spaces?! Sacrilege!!!!!1!
:-)
OK we'll see what we can do here.
I think this is an example of one of the weak areas of generating a JSON document. If you have a Map or a List already, then these facilitate creation of a JsonObject or JsonArray with the contents. But the Map values and List elements need to be JsonValues, so something needs to convert them. You could do so with a stream, or you could construct an unmodifiable Map or List with JsonValues converted from other data you have at hand.
But maybe there's a better way to do this. Do you need to gather all the data up front and then construct the JsonObject? Or should you pass around a HashMap and build it up incrementally? Or should there be a way to build up a JsonObject itself incrementally, using a builder? It's pretty easy to come up with a bunch of API shapes to do this kind of stuff. What's harder is figuring out which approaches are useful and effective. That's why I often ask for use cases when people are discussing API designs.
By "use cases" I'm not looking for "I want to build a JsonObject from a Map<K,V> employing user-defined conversion methods for K and V." That's just a restatement of a proposed solution in requirements form. I also don't want "I'm working on a CRM web app." That's too high level to provide any meaningful direction for an API.
Instead, what I'm looking for is information about the object structure and organization that is going to produce (or be mined for) data that ends up in the JSON document. For example:
I'm mostly interested in examples of the fourth point!
Also, if you have use cases about transforming documents, what do those look like? Are you filtering objects to trim down an array? Are you filtering members or adding new members to objects of interest? Are you querying different members of different objects to form new objects? Are you changing the structure of the document? Also, do you actually transform documents directly, or do you roll a JSON document into internal data structures, process them, and then generate a new, independent JSON document from internal data?
Thanks!!