TinyJson is a json data parser library for Java.
The parser is well tiny, very suitable for temporary use or small projects.
It's small and faster than org.json
Lets get started!
Creat a JsonObject
JsonObject jsonObject = new JsonObject();Parse JsonObject, and get value
String rawData = "{\"Hello\":\"World\", \"age\":17}";
JsonObject result = new JsonObject(rawData);
System.out.println(result.getString("Hello"));
System.out.println(result.getInt("age"));Get ListedJsonObject length
ListedJsonObject listedJsonObject = new ListedJsonObject("{\"Hello\":\"World\"}");
System.out.println(listedJsonObject.length);Creat a JsonArray
JsonArray jsonArray = new JsonArray();Parse jsonArray, and get value
String rawData = "[\"Hello\", \"World\", 17]";
JsonArray result = new JsonArray(rawData);
System.out.println(result.getString(0));
System.out.println(result.getString(1));
System.out.println(result.getInt(2));Get length
JsonArray jsonArray = new JsonArray("[\"Hello\", \"World\", 17]");
System.out.println(jsonArray.length);For loop
String rawData = "[\"Hello\", \"World\", 17]";
JsonArray result = new JsonArray(rawData);
for (Object i : result) {
System.out.println(i);
}Maven
<dependency>
<groupId>io.github.WavJaby</groupId>
<artifactId>tiny-json</artifactId>
<version>0.0.4</version>
</dependency>Gradle
dependencies {
//Change 'implementation' to 'compile' in old Gradle versions
implementation 'io.github.WavJaby:tiny-json:0.0.4'
}
repositories {
mavenCentral()
}-
toString()get json string -
toStringBeauty()get the json string, with line breaks and tabs -
addAll(jsonObject)add all key and value from other jsonObject -
put(key, value)put a value into JsonObject -
remove(key)remove a value from JsonObject -
containsKey(key)return true, if there is a key in JsonObject -
notNull(key)return true, if there is a key in JsonObject and the value is not null -
getJson(key)get JsonObject -
getArray(key)get JsonArray -
getString(key)get String -
getInt(key)get int value -
getLong(key)get long value -
getBigInteger(key)get BigInteger value -
getFloat(key)get float value -
getDouble(key)get double value -
getBigDecimal(key)get BigDecimal value -
getBoolean(key)get boolean value -
getObject(key)get value as Object -
get(key)get value
-
toString()get json array string -
toStringBeauty()get the json array string, with line breaks and tabs -
add(value)add a value into JsonArray -
addAll(jsonArray)add all value from other jsonArray -
set(index, value)set a value in JsonArray -
remove(index)remove a value from JsonArray -
toArray(index)to Object array -
content(value)check if JsonArray content value -
indexOf(value)the index of a value in JsonArray -
getJson(index)get JsonObject -
getArray(index)get JsonArray -
getString(index)get String -
getInt(index)get int value -
getLong(index)get long value -
getBigInteger(index)get BigInteger value -
getFloat(index)get float value -
getDouble(index)get double value -
getBigDecimal(index)get BigDecimal value -
getBoolean(index)get boolean value -
getObject(index)get value as Object -
get(index)get value