Date:

Share:

JSON.simple vs GSON vs Jackson vs JSONP

Related Articles

Which JSON library for Java can analyze JSON files the fastest?

  • Originally Posted: May 28, 2015
  • Updated August 13, 2017
  • Updated October 5, 2021

JSON is the currently accepted standard for data transfer between servers and web applications. We often do not think about the JSON libraries we use, but there are some differences between them.

JSON is often used to transfer and analyze large files. This is a common scenario in data processing applications running in Hadoop or Spark clusters. Given the size of these files, you can look at significant differences in the speed of analysis between directories.

Small files keep coming up as high-yield incoming requests, and their analysis takes place quickly, so the differences in performance do not seem like a big deal at first. But the differences add up, because you often have to analyze a lot of small files in quick succession in times of heavy traffic. Micro-services and distributed architectures often use JSON to transfer such files, as this is the de facto format for web APIs.

Not all JSON libraries work the same. Choosing the right one for your environment can be critical. We ran a benchmark test to see how fast the four most popular JSON libraries for Java parse files of different sizes. This metric can help you decide.

JSON LIBRARIES

JSON.simple vs. GSON vs. Jackson vs. JSONP For comparison tests, we tested four major JSON libraries for Java: JSON.simple, GSON, Jackson, and JSONP. All of these libraries are in popular use for JSON processing in the Java environment, and have been selected based on their popularity in Github projects. Here are the ones we tested:

  • Yidong Fang’s JSON.simple: https://github.com/fangyidong/json-simple

    JSON.simple is a Java toolkit for encoding and decoding JSON text. It is supposed to be a lightweight and simple library that still functions at a high level.
  • Google’s GSON: https://github.com/google/gson

    GSON is a Java directory that converts Java objects to JSON and vice versa. It provides the added benefit of full Java Generics support, and does not require you to comment on your lessons. Not having to add comments makes the application simpler and may even be a requirement if you do not have access to your source code.
  • FasterXML’s Jackson Project: https://github.com/FasterXML/jackson

    Jackson is a set of data processing tools highlighted by the JSON flow analyzer and its generator library. Designed for Java, it can also handle non-JSON encodings. This is the most popular JSON parser, according to our findings on the usefulness of Github.
  • Oracle’s JSONP: https://jsonp.java.netJSONP (JSON Processing) is a Java API for JSON processing, i.e. around consumption and production of flowing JSON text. This is the JSR353 open source referral application.

Index: 2017

We ran a benchmark test on the directories for both large and small files. The requirements (and therefore the performance) for handling different file sizes, as well as the environments in which the need to analyze these files arises.

The index examined two main scenarios: analysis speed for large files (190 MB) and analysis speed for small files (1 KB). The large files were taken from here: https://github.com/zeMirco/sf-city-lots-json. The small files were created randomly from here: http://www.json-generator.com/.

For both large and small files, we ran each file 10 times per directory. Given the size of the large file, we did 10 iterations per session for each directory. Each small file passed 10,000 times in each session for each directory. For testing the small files, we did not keep the files in memory between iterations and the test was performed on the c3.large instance in AWS.

The results for the large file are presented in full below, but I further measured the average of the results for the small files in favor of space. To view the extended results, Come here. If you want to see the source code of the small files or directories, Come here.

Large File Results: 2017

Big differences here! Depending on the run, Jackson or JSON.simple traded at the fastest times, with Jackson allocating JSON.simple cumulatively. When looking at the average result in all test runs, Jackson and JSON.simple come out well ahead of the big file, with JSONP in the far third place and GSON in the last place.

Let’s put it in percentages. Jackson is the average time winner in all runs. Looking at the numbers from two different angles, here are the results in percent:

table 3
These are big differences between library speeds!

Remove: It was a photo shoot, but Jackson is your winning library. JSON.simple is also in the back and the other two are in the rearview mirror.

Small file results: 2017

table 2 1

The table above shows the average of 10 runs per file, and the total average at the bottom. The number for the fastest directory on the number of files we won is:

  • GSON – 14
  • JSONP – 5
  • Jackson – 1
  • JSON.simple – 0

Looking at the average result of all the test runs across all the files, GSON is the winner Here, where JSON.simple and JSONP occupy a distinct second and third place, respectively.

Jackson came in second last. So even though it is not the fastest in any single file, JSON.simple is the second fastest in the aggregate. And despite being the fastest in a handful of files, JSONP ranks third overall.

Jackson is very consistent across all files, while the other three libraries occasionally are much faster than Jackson, but in some files end up running at about the same speed or even a little slower.

Let’s multiply the numbers by a percentage, again let’s look at the numbers from two different angles:

table 4

Compared to the large file tests, these are smaller differences, but still quite noticeable.

Remove: Bad luck for JSON.simple, as he again loses in a close race, but GSON is your winner. JSONP is a clear third and Jackson raises the back.

Conclusion: 2017

Analysis speed is not the only consideration when choosing a JSON library, but it is important. After running this index test, what we found is that there is no one directory that throws the others at the speed of analysis in all file sizes and all runs. The libraries that did well with large files suffered from small files and vice versa.

The choice of which library to use thanks to the speed of surgery then depends on your environment.

  • If you have an environment that often or mostly deals with large JSON files, then Jackson Is your library of interest. GSON struggles the most with large files.
  • If your environment is primarily concerned with a lot of small JSON requests, like micro-services or distributed architecture definition, then GSON Is your library of interest. Jackson struggled the most with small files.
  • If you end up having to deal with both types of files frequently, JSON.simple Reached 2nd place very close in both tests, making it a good workhorse for a changing environment. Neither Jackson nor GSON function equally well in multiple file sizes.

As for the speed of analysis, JSONP does not have much to recommend for it in any scenario. Poor performance for large and small files compared to other available options. Fortunately, according to reports, Java 9 gets an original JSON application, which could have been imagined to be an improvement over the reference implementation.

If you are concerned about the analysis speed of your JSON directory, select Jackson for large files, GSON for small files and JSON.simple to handle both.

Index: 2021

We ran the same criteria again, but we are now using the latest libraries and running the tests in Java 11.

The numbers look completely different from what we’ve run these metrics in the past. In general, performance has risen drastically.

Results of large files: 2021

json benchmark 2021 big files

Recent criteria Jackson Was the winner, but this time GSON Is by far the fastest, with JSONP Be a close second and then Jackson and then JSON.simple Latest.

And again look at the numbers from two different angles, below are the results in percent:

GSON He is a clear winner.

json benchmark image 2

Result of small files: 2021

In the small file Results Gasson He’s still the winner. Clearly defeats the other 3 contestants.

json benchmark 2021 small files

Here are the results:

  1. Gasson
  2. Jsonp
  3. Json.simple
  4. Jackson

Gasson Processes these files faster by almost 200+ milliseconds before the next candidate.

Conclusion: 2021

The obvious elephant in the room is that java and json libraries have become faster. As if much faster than then, when the first indices were conducted.

It’s also clear GSON Went up big and won both metrics for large and small files. In both cases it is very clear.

Source

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Popular Articles