Java JSON Tutorials

json logo

JSON, which stands for JavaScript Object Notation, is a lightweight text-based data format that is easy for humans to read and write and for machines to parse and generate. It is commonly used for transmitting data or data exchange in web applications (e.g., sending some data from the server to the client, so it can be displayed on a web page, or vice versa).

Table of contents

1. JSON Data Format

Below are some of the standard JSON structures:

Basic JSON Strings
This is how a JSON message look likes:


  {
    "name": "mkyong"
  }

JSON Object
JSON can contains strings, numbers, arrays, booleans, and other object literals.


  {
    "name": "mkyong",
    "age": 42
    "skills": ["react", "python"],
    "active": true
  }

JSON Array
Array of JSON objects.


  [
    {
      "name": "mkyong",
      "age": 20
    },
    {
      "name": "ah pig",
      "age": 40
    },
    {
      "name": "ah dog",
      "age": 30
    }
  ]

2. Java JSON Libraries

List of the Java JSON libraries

2.1 Jackson

Jackson is a high-performance JSON processor for Java, known as the "Java JSON library", the most popular JSON framework in Java, picks this if you are not sure which to pick.

P.S. All Jackson examples are tested with Jackson 2.17.0.

2.2 Google Gson

Gson is a Java library used to convert Java Objects into their JSON representation and vice versa.

P.S. All Gson examples are tested with Jackson 2.10.1.

2.3 Moshi

Moshi is a modern JSON library for Android, Java and Kotlin. It makes it easy to parse JSON into Java and Kotlin

P.S. All Moshi examples are tested with Moshi 1.15.1.

2.4 JSON.simple

The JSON.simple library is a lightweight utility for deserializing and serializing Javascript Object Notation (JSON).

P.S. All JSON.simple examples are tested with json-simple 4.0.1.

2.5 FastJson

Tested with FastJson 1.2.57 (Need Update)

3. FAQs

4. Download Source Code

$ git clone https://github.com/mkyong/java-json

$ cd gson

5. References

Image

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments