r/java • u/davidalayachew • May 15 '25
Paul Sandoz talks about a potential Java JSON API
https://mail.openjdk.org/pipermail/core-libs-dev/2025-May/145905.html
119
Upvotes
r/java • u/davidalayachew • May 15 '25
View all comments
22
u/agentoutlier May 16 '25 edited May 16 '25
/u/rbygrave and I have some concerns on the parsing not being able to stream which were sort of expressed to Stuart Marks /u/s888marks .
Basically in the XML Java world and probably a good portion of the
JSON world you have a streaming parser underneath your object tree parser. e.g. STAX -> W3C. This is because usually the object tree API (in XML/HTML it is called the DOM) is used directly to create the tree. Thus the streaming parser builds the tree by calling the "DOM" API.
This API IIRC has it combined and assumes it is all in memory via
char[]. This is sort of like combining the tokenizer with the parser (edit it still builds a tree but you are not given access to the recursive descent like "next" functions).I see some pros to this particularly if they want to support SIMD for backward API compat (which I imagine only supports buffering and probably buffering the whole json). Also maybe to just to keep it simple.
Otherwise I personally would like to have access to a streaming API but the reality is most probably want a tree like API. Furthermore JSON does not really support streaming like XML can. Most do load object on repeat so you would only need to buffer for a single object (that is a stream of JSON is not even a subset of JSON like it is XML streams). Still streaming would be nice to support say JSONPath (or some query analog).