Package jsonvalues
json-values is a one-package and zero-dependency library to work with jsons in a declarative and functional way.
From now on, an immutable object is a value. There are different static factory methods to create objects:
of
methods to create values.parse
methods to parse strings into immutable values._of_
methods to create mutable objects._parse_
methods to parse strings into mutable objects.
- 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.mapKeys_(toUppercase) = {"A":1, "B":[{"C":1, "D":true}]}
-
Interface Summary Interface Description JsArray Represents a json array, which is an ordered list of elements.JsElem Represents a json element of any type.JsNumber Represents an immutable json number.JsObj Represents a json object, which is an unordered set of name/element pairs.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.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 JsElem in a JsArray.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.JsPair Immutable pair which represents a JsElem of a Json and its JsPath location: (path, element).JsPath Represents the full path location of an element in a json.JsStr Represents an immutable json string.Key Represents the Key of a JsElem in a JsObj.MatchExp Java doesn't support Pattern Matching but we can implement some matching expressions using high order functions.ParseBuilder Builder with different transformations to customize the parsing of a string into a json.Patch Encapsulates a RFC 6902 implementation.Patch.Builder represents a builder to create json-patch operations according to the RFC 6902 specification.Try Computation that parses a string into a Json and may either result in a MalformedJson exception or a successfully parsed json.TryArr Computation that parses a string into a JsArray and may either result in a MalformedJson exception or a successfully parsed array.TryObj Computation that parses a string into a JsObj and may either result in a MalformedJson exception or a successfully parsed object.TryPatch<T extends Json<T>> Computation that applies a group of operations to a Json according to the RFC 6902 and may either result in a PatchMalformed or PatchOpError exceptions, or a successfully transformed json. -
Enum Summary Enum Description JsArray.TYPE Type of arrays: SET, MULTISET or LIST. -
Exception Summary Exception Description InternalError Exception that models an internal error made by a developer.MalformedJson Exception returned when a string can not be parsed into a Json or the json parsed has a different type than the expected.PatchMalformed Represents an error when an operation has a invalid schema and the patch can not be applied.PatchOpError Represents an error applying a patch.UserError Exception that models a programming error made by the user.