Package jsonvalues

json-values is a one-package and zero-dependency library to work with jsons in a declarative and functional way. There are different static factory methods to create objects:
  • of methods to create immutable objects or values from primitive types.
  • parse methods to parse strings into immutable objects or values.
  • _of_ methods to create mutable objects from primitive types.
  • _parse_ methods to parse strings into mutable objects.
Only three exceptions are thrown by the library:
  • the unchecked UnsupportedOperationException, when the client makes a programming error.
  • the checked MalformedJson, when a string can not be parsed into a json.
  • the unchecked NullPointerException, when a method receives a null parameter.
All the methods which name ends with underscore are applied to the whole json recursively, and not only to the first level. For example:
 
 x={"a":1, "b":[{"c":1, "d":true}]}
 x.size() = 2  // a and b
 x.size_() = 3 // a, b.0.c and b.0.1
 x.mapKeys(toUppercase)  =  {"A":1, "B":[{"c":1, "d":true}]}
 x.mapKeys_(toUppercase) =  {"A":1, "B":[{"C":1, "D":true}]}