Incremental JSON Streaming Library for Java

Can anyone recommend a JSON library for Java that allows me to give it chunks of data when they come in without blocking? I read the Best Java JSON library and similar questions, and did not find exactly what I wanted.

Essentially, I need a library that allows me to do something like the following:

String jsonString1 = "{ \"A broken"; String jsonString2 = " json object\" : true }"; JSONParser p = new JSONParser(...); p.parse(jsonString1); p.isComplete(); // returns false p.parse(jsonString2); p.isComplete(); // returns true Object o = p.getResult(); 

Note that the actual key name ("Broken json object") is shared between the parts.

The closest I found is async-json-library , which does almost what I would like, except that it cannot restore objects where actual rows or other data values ​​are shared between parts.

+4
source share
3 answers

There are several blocking streaming / incemental JSON parsers (according to Is there a streaming API for JSON? ); but for asynchronous nothing i know. You are referring to lib, which is poorly named; it does not seem to perform real asynchronous processing, but simply allows you to parse a sequence of JSON documents (which also allows several other libs)

If there were people who really wanted this, writing one thing is not impossible - there is Aalto for XML, and JSON processing is quite simple than XML. For what it's worth, this function request to add a non-blocking parsing mode for Jackson ; but very few users have expressed interest in doing this (by voting on feature request).

EDIT: (2016-01), while not async, Jackson ObjectMapper allows a convenient subtree to bind parts of the tree also using a tree structure - see ObjectReader.readValues() ( ObjectReader created from ObjectMapper ), or abridged versions of ObjectMapper.readValues(...) . Pay attention to the final s , which implies a stream of objects, not just one.

+2
source

Google Gson can gradually parse Json from InputStream https://sites.google.com/site/gson/streaming

0
source

I wrote a parser like this: JsonParser.java . Examples of use: JsonParserTest.java .

0
source

All Articles