A Fast, Flexible JSON Library for Java

A Fast, Flexible JSON Library for Java
A Fast, Flexible JSON Library for Java
There's a new JSON library on the block that promises high performance with tricks like dynamic class shadowing and quick data binding.

Don't we already have objectMapper.readValue? Why another JSON library? I found myself stuck in a couple of situations, and jsoniter (json-iterator) really worked for me:

Also, jsoniter is much much faster than existing libraries (jackson, gson, you name it). Third party benchmarking is welcome. Here are the shameless self-benchmarking results for data binding 1kb of JSON:

The advantages of jsoniter come from these innovations:

Required field validation : When you parse an object of int field. You can not tell the field is zero because no input from JSON or the field is indeeded specified as zero. Jsoniter implemented required field tracking using bit mask, now you can know.

A lot of work has been done to make sure jsoniter is the fastest out there. Benchmarking aside, what most people truly want is to get their job done fast. Here is an example to show you how flexible the API is:

[1024, {"product_id": 100, "start": "beijing"}] ["1025", {"product_id": 101, "start": "shanghai"}] // many many more lines

Each line is an object. The first element is the order ID, and the second element is the order details. Notice:

In 6 lines, we have solved all the problems.

JsonIterator iter = JsonIterator.parse(input); // input stream OrderDetails orderDetails = new OrderDetails(); // reused while(iter.whatIsNext() != ValueType.INVALID) { Any order = iter.readAny(); // lazy int orderId = order.toInt(0); // weakly typed String start = order.get(1).bindTo(orderDetails).start; // data binding }

This example is just a demo of the flexibility. It might seems overly complex, it will be handy when you need it though. For everyday use, just remember two lines:

JsonIterator.deserialize("[1,2,3]"); // JSON => object JsonStream.serialize(new int[]{1,2,3}) // object => JSON

I hope you are interested. This library is new, so bug reports or pull requests should be submitted to https://github.com/json-iterator/java . The Golang version will be available soon.