Another JSON Library for Java.
This one however emphasises the safe composition and dynamic manipulation of JSON structure.
Contrary to most other java JSON libraries, nemesis makes one view and manipulate JSON as a proper data structure, as opposed to something that should be coerced to some domain-object. (think Jackson JsonNode, but better)
It is, as such, somewhat of a nemesis to most other JSON libraries.
For a slightly more detailed introduction and rationale, please take a look here.
Not necessarily battle tested.
Supports Java 1.8 and upwards
<dependency>
<groupId>com.ravram</groupId>
<artifactId>nemesis</artifactId>
<version>0.2.0</version>
</dependency>
public static void main (String... args) {
String json1 = "{ \"hello\" : \"world\" }";
String json2 = "{ \"numbers\" : [{ \"first\" : 1 }, { \"second\" : 2 }] }";
Either<String, String> modified = parse(json1)
.insertValue("Mark", "Oh-Hai")
.insertValue("value", "Deep", "Nested", "Structure")
.remove("hello")
.mergeJson(parse(json2))
.updateValue(JSON_TO_LONG, a -> a + 1, "numbers", 1, "second")
.affix()
.map(json -> json.encode());
System.out.println(modified);
}
// Right:
// {
// "Deep":{
// "Nested":{
// "Structure":"value"
// }
// },
// "numbers":[
// { "first":1 },
// { "second":3 }
// ],
// "Oh-Hai":"Mark"
// }
See API for more details and examples.
See Benchmarks for some performance related information.
Copyright © 2021 Robert M. Avram
Distributed under the MIT License.