https://github.com/lavajuno/lucidjson
Straightforward JSON serialization & deserialization library for Java.
https://github.com/lavajuno/lucidjson
java json ll-parser parser serialization
Last synced: 8 days ago
JSON representation
Straightforward JSON serialization & deserialization library for Java.
- Host: GitHub
- URL: https://github.com/lavajuno/lucidjson
- Owner: lavajuno
- License: mit
- Created: 2024-01-15T01:36:50.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T21:23:35.000Z (about 1 year ago)
- Last Synced: 2024-10-29T23:44:21.758Z (about 1 year ago)
- Topics: java, json, ll-parser, parser, serialization
- Language: Java
- Homepage: https://lavajuno.github.io/lucidjson/
- Size: 201 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lucidjson
Straightforward JSON serialization & deserialization library for Java.
[Source Code](https://github.com/lavajuno/lucidjson)
[Releases](https://github.com/lavajuno/lucidjson/releases)
[Documentation](https://lavajuno.github.io/lucidjson/docs/index.html)
## Features
- Easy-to-use dynamic JSON objects
- Simple interface for serialization/deserialization of classes
- Serialize as minified or pretty JSON
- Descriptive error reporting
## Usage Examples
> Note: These are very basic examples and will be updated to include more realistic use cases.
Deserializing a JSON object from a string:
```java
import org.lavajuno.lucidjson.JsonObject;
public static void main(String[] args) {
String s = "{ \"myKey\": \"myValue\" }";
JsonObject o = JsonObject.from(s);
}
```
Serializing a JSON object to a string:
```java
import org.lavajuno.lucidjson.JsonObject;
public static void main(String[] args) {
String s = o.toJsonString(true);
}
```
> Note: The above methods are identical for JSON arrays.
Modifying JSON objects:
```java
import org.lavajuno.lucidjson.JsonObject;
import org.lavajuno.lucidjson.JsonString;
public static void main(String[] args) {
JsonObject o = JsonObject.from("{ \"myKey\": \"myValue\" }");
o.put("myKey2", new JsonString("myValue2"));
}
```
Implementing JsonSerializable for a class:
```java
import org.lavajuno.lucidjson.JsonNumber;
public class User implements JsonSerializable {
private String name;
private int age;
public User() {
name = "";
age = -1;
}
@Override
public JsonObject toJsonObject() {
JsonObject o = new JsonObject();
o.put("name", new JsonString(name));
o.put("age", new JsonNumber(age));
return o;
}
@Override
public void fromJsonObject(JsonObject o) {
this.name = ((JsonString) o.get("name")).value();
this.age = ((JsonNumber) o.get("age")).toInt();
}
}
public static void main(String[] args) {
String s = "{\"name\":\"bob\",\"age\":12345}";
User a = new User();
a.fromJsonString(s); // deserialize from JSON string
String s = a.toJsonString(); // serialize to JSON string
}
```
> Classes only need to implement toJsonObject() and fromJsonObject().
> Serialization / deserialization to and from strings is handled by the interface.
>
> This behavior can be overridden if desired.
## Use Cases
lucidjson is designed to allow you to easily write custom JSON serialization & deserialization
functions for classes. It can also be used to modify JSON documents without loading them
into a rigid class structure.
## Licensing
lucidjson is Free and Open Source Software, and is released under the MIT license. (See [`LICENSE`](LICENSE))