Package jsonvalues
json-values is a one-package and zero-dependency library to work with jsons in a declarative and functional way.
The main exceptions thrown by the library are the following:
- the custom unchecked
UserError
, when the client makes a programming error. A suggestion in the message to avoid the error is returned. - the custom unchecked
InternalError
, when something unexpected happens because a developer made a mistake. An issue in GitHub must be created - the checked
MalformedJson
, when a string can not be parsed into a json. - the unchecked NullPointerException, when a method different than equals receives a null parameter.
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.mapAllKeys(toUppercase) = {"A":1, "B":[{"C":1, "D":true}]}
-
Interface Summary Interface Description Json<T extends Json<T>> Represents a json of type T, where T is the type of the container, either a JsObj or a JsArray.JsValue Represents a json element of any type.Position Represents the location of a first-level element in a json, either a Key in a JsObj or an Index in a JsArray.Trampoline<T> Trampolines allow to define recursive algorithms by iterative loops without blowing the stack when methods implementations are tail recursive. -
Class Summary Class Description Index represents the index of a value in an json array.JsArray Represents a json array, which is an ordered list of elements.JsBigDec Represents an immutable json number of type BigDecimal.JsBigInt Represents an immutable json number of type BigInteger.JsBool Represents an immutable json boolean.JsDouble Represents an immutable json number of type double.JsInt Represents an immutable json number of type integer.JsLong Represents an immutable json number of type long.JsNothing It's a special json element that represents 'nothing'.JsNull Represents null, which a valid json value.JsNumber Represents an immutable json number.JsObj Represents a json object, which is an unordered set of name/element pairs.JsObjLens<S extends Json<S>> Represent a Lens which focus is a json object located at a path is a JsonJsOptics represents optics defined for json objects and arraysJsOptics.JsArrayLenses represents all the lenses defined for a Json arrayJsOptics.JsArrayOptics represents all the optics defined for a Json arrayJsOptics.JsArrayOptionals represents all the S defined for a Json arrayJsOptics.JsObjLenses represents all the lenses defined for a Json objectJsOptics.JsObjOptics represents all the optics defined for a Json objectJsOptics.JsObjOptional represents all the S defined for a Json objectJsPair Immutable pair which represents a value and its location: (path, value).JsPath Represents the full path location of an element in a json.JsStr Represents an immutable json string.Key represents the key of a value in a json objectLens<S,O> A Lens is an optic that can be seen as a pair of functions:- get: S => O i.e. from an S, we can extract an O - set: (O, S) => S i.e. from an S and a O, we obtain a S. Unless a prism, to go back to S we need another S.
Typically a Lens can be defined between a Product (e.g.Option<S,T> An Optional is an optic that allows seeing into a structure and getting, setting, or modifying an optional focus.Prism<S,T> A Prism is an optic that can be seen as a pair of functions:- getOptional: S -> Optional<T> - reverseGet : T -> S
Typically a Prism encodes the relation between a Sum or CoProduct type and one of its element. -
Enum Summary Enum Description JsArray.TYPE Type of arrays: SET, MULTISET or LIST. -
Exception Summary Exception Description MalformedJson Exception returned when a string can not be parsed into a Json or the json parsed has a different type than the expected.UserError Exception that models a programming error made by the user.