Skip to content

iahmadgad/json-java

Repository files navigation

Java JSON

Gradle Javadoc

Java implementation of JSON.

A beginner project that I am proud of, because I worked hard on it.

I aim to enhance it further & further إن شاء الله, but when I finish this year, my last year in school :')

Features

  • Read JSON strings & files.
  • Generate JSON strings & write them into files.
  • Convert JSON objects to Java objects & vice versa.
  • Access JSON fields using JSON pointers.
  • supports nested JSON objects & arrays.

Examples

Initialise a new JSON object

JSONObject obj = new JSONObject();
obj.put("$id", "User-info");
obj.put("name", "Gelobt");
obj.put("age", 16);
obj.put("isAlive", true);

Initialise a new JSON array

JSONArray arr = new JSONArray();
arr.add("Java");
arr.add("C++");
arr.add("Cats");

Put JSON array into JSON object

obj.put("THINGS I LOVE", arr);

Write JSON object into file

obj.write(new File("User-info.json"));

The file should look like this:

{
     "isAlive":true
     ,"name":"Gelobt"
     ,"THINGS I LOVE":     [
          "Java"
          ,"C++"
          ,"Cats"
     ]

     ,"age":16
     ,"$id":"User-info"
}

Releases

No releases published

Packages

No packages published

Languages