JSON with Java


What is JSON ?

JSON stands for javascript object notation. JSON is a lightweight, text-based language that makes it easy to read and write for humans and machines. JSON provides two structures, object, and array. The object is an unordered collection of zero and more value, whereas an array is an ordered collection of zeros and more values. JSON is extended from javascript; it is independent and easy to read and write the language.

JSON with Java

Before you start coding with JSON in java, you need to install JSON. Also, you need a json-simple-1.1.1.jar file in your JDK. The org.json.simple contains various classes for json API, which are,

  • JSONValue
  • JSONObject
  • JSONArray
  • JSONString
  • JSONNumber

This is the format in which JSON stores the data. Here stu_id, stu_name and course name is getting stored which we can access using object.

Mapping between Json and Java entities

JSON simply maps the entities from left to right while decoding or parsing the data, and maps from right to left while encoding. Following are some entities used in JSON and Java for the same purpose.

JSON Java
String java.lang.string
Number java.lang.number
null null
array java.util.list
object java.util.map
true/false java.lang.boolean