Jsonic is a lightweight JSON parsing and generation library for Java. It provides a simple, object-oriented API for working with JSON data without external runtime dependencies.
Jsonic offers a straightforward approach to JSON manipulation with the following capabilities:
JSON Parsing - Parse JSON from strings or Reader objects with a clean, type-safe API
JSON Generation - Build JSON structures programmatically using a fluent builder pattern
Type Safety - Access JSON values with type-specific methods like asObject(), asArray(), asString()
Minimal Dependencies - Zero runtime dependencies, keeping your project lean
Simple API - Intuitive methods that make JSON manipulation straightforward
Java 21 or higher
Maven 3.x for building
Clone the repository and build with Maven:
git clone https://github.com/ISmillex/jsonic.git
cd jsonic
mvn clean installParse JSON from a string and access values:
import org.smilex.jsonic.Jsonic;
import org.smilex.jsonic.JValue;
String jsonString = """
{
"name": "John Doe",
"age": 30,
"active": true
}
""";
JValue json = Jsonic.parse(jsonString);
String name = json.asObject().get("name").asString();
int age = json.asObject().get("age").asNumber().intValue();
boolean active = json.asObject().get("active").asLiteral().booleanValue();Create JSON structures programmatically:
import org.smilex.jsonic.Jsonic;
import org.smilex.jsonic.JObject;
import org.smilex.jsonic.JArray;
JObject person = Jsonic.object()
.add("name", "Jane Smith")
.add("email", "jane@example.com")
.add("roles", Jsonic.array()
.add("admin")
.add("user"));
String jsonString = person.toString();JArray items = Jsonic.array();
items.add(Jsonic.object()
.add("id", 1)
.add("product", "Widget")
.add("price", 19.99));
items.add(Jsonic.object()
.add("id", 2)
.add("product", "Gadget")
.add("price", 29.99));
// Access array elements
for (JValue item : items) {
String product = item.asObject().get("product").asString();
double price = item.asObject().get("price").asNumber().doubleValue();
}try (Reader reader = new FileReader("data.json")) {
JValue json = Jsonic.parse(reader);
// Process JSON data
}Jsonic - Main factory class with static methods for creating and parsing JSON
JValue - Abstract base class for all JSON values
JObject - Represents JSON objects (key-value pairs)
JArray - Represents JSON arrays
JString - Represents JSON strings
JNumber - Represents JSON numbers
JLiteral - Represents JSON literals (null, true, false)
Jsonic.parse(String) - Parse JSON from a string
Jsonic.parse(Reader) - Parse JSON from a Reader
Jsonic.object() - Create a new JSON object
Jsonic.array() - Create a new JSON array
JValue.asObject() - Cast value to JObject
JValue.asArray() - Cast value to JArray
JValue.asString() - Cast value to JString
JValue.asNumber() - Cast value to JNumber
JValue.asLiteral() - Cast value to JLiteral
The project uses Maven for build management. To build:
mvn clean compileTo run tests:
mvn testTo create a JAR file:
mvn packageThis project is open source. Please check the LICENSE file for details.
Contributions are welcome. Please submit pull requests or open issues for bugs and feature requests.