Skip to content

AvramRobert/nemesis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nemesis

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.

Disclaimer

Not necessarily battle tested.

Dependency

Supports Java 1.8 and upwards

<dependency>
  <groupId>com.ravram</groupId>
  <artifactId>nemesis</artifactId>
  <version>0.2.0</version>
</dependency>

Usage

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.

License

Copyright © 2021 Robert M. Avram

Distributed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published