JSON Simple example – Read and write JSON

JSON Simple example show you how to use JSON.simple Java library for reading and writing JSON data into a file.
JSON.simple, is a simple Java library for JSON processing and full compliance with JSON specification (RFC4627).

Other interesting posts you may like

In this tutorial, we show you how to use JSON.simple to read and write JSON data from / to a file.

Project structure directory
In this JSON Simple example, we will create java project with directory structure like below:

JSON Simple example

Maven dependencies

We should provide JSON.simple Dependency in pom.xml file like below

Create a program that write JSON to file
In this example, it initializes data via JSONObject and JSONArray. Then save it into a file named “test.json” that is placed in the directory “E:\tmp”.

Run the above program as java application and get the output in the file “test.json” like below:

Create a program that read JSON from file
In this program, we use JSONParser to read above the generated JSON file “test.json” and display it’s content

Run above program as java application and output will be generated like below:

Noticed that if you want to convert object to / from JSON, you should consider Jackson or Gson.
That’t it on the JSON Simple example tutorial.

Download source code, click link below

jsonsimple-example.zip

3 thoughts on “JSON Simple example – Read and write JSON

  1. Greate pieces. Keep posting such kind of information on your site.
    Im really impressed by it.
    Hello there, You have performed an excellent job. I
    will certainly digg it and individually suggest to my friends.

    I am sure they will be benefited from this site.

Leave a Comment

*

Please share it if you found this useful
Hide Buttons