The umbrella of utilities for Json Manipulation, Json Conversion and Json transformation in Java.
It is vaguely similar to lodash's object manipulation capabilities but adds a lot more punch to
it.
Json mystique ships a set of libraries written in and for Java, useful for json manipulation & transformation
- Json Manipulation
The library exposes simpleget
,set
anddefault
methods for json manipulation.
Refer JsonLever, GsonConvertor, JacksonConvertor, JsonQuery and JsonComparator for more details.Eg. JsonElement json = { 'a': [{ 'b': { 'c': 3 } }] }; jsonLever.get(json, 'a.0.b.c'); // => 3
- Json Transformation
The library takes an input json as a string or JsonElement and transforms the same to a json string or JsonElement.
The transformation is performed via a ruleSet file that specifies the mappings in a json format.
Refer JsonMystique for more details.
- The library is useful for simple Json representation, access and manipulation in Java
Refer JsonLever for more details
Eg. JsonElement json = { 'a': [{ 'b': { 'c': 3 } }] }; jsonLever.get(json, 'a.0.b.c'); // => 3 jsonLever.get(object, ["a", "0", "b", "c"]); // => 3 jsonLever.get(object, "a.b.c", "default"); // => "default"
- The library is useful for transforming from one json to another, even when the input and output jsons are non
identical
- Multiple fields from the input can be operated on to map to a single field in the output
- Custom converters can be easily plugged to handle custom domain logic Refer JsonMystique for more details.
- The library exposes a standard interface for converting POJO to json and vice versa
- The library is useful for getting subset or projections of a json object.
Refer JsonLever for more details - The library is useful for comparing two jsons
- Compare if two jsons are identical
- Compare if one json is a subset of another Refer JsonComparator for more details
- The library exposes a query interface on a json, to perform various 'sql'-like queries on a json and select relevant
fields from it.
Refer JsonQuery for more details
- The library requires Java 17+
- The library uses maven for its build management
- The library can be primarily used as a stand-alone java lib and depends on
- Gson - 2.11.0 for json String to Java pojo transformations
- Jackson - 2.17.2 for json String to Java pojo transformations
- For the Spring fan-boys, Json Mystique also ships a Spring-Starter, which depends on
The actual versions can be found in the pom file
Json Mystique and all its libraries
download at Maven Central.
The different library utils, their capabilities & their maven dependency snippets are detailed below:
<dependency>
<groupId>com.balajeetm.mystique</groupId>
<artifactId>json-mystique</artifactId>
<version>2.5.3</version>
</dependency>
NOTE
There are three variants of JsonMystique.
The1.x.x
and0.x.x
versions have reached EOL.2.x.x
is the only active version as of now
2.x.x - Standalone json transformation utility
1.x.x - Parallel processing json transformation utility
0.x.x - Sequential processing json transformation utility
NOTE 2.2.x onwards supports Spring Boot 2.1.X
NOTE
2.x.x is the only supported version currently since the parallel processing logic is mainstream. The other versions (0.x.x and 1.x.x) have been deprecated.
It is highly recommended and suggested, to only use the 2.x.x versions of Mystique.
Please raise issues, for support if any, on earlier versions.
<dependency>
<groupId>com.balajeetm.mystique</groupId>
<artifactId>json-mystique-starter</artifactId>
<version>2.5.3</version>
</dependency>
The custom spring-boot-starter for JsonMystique. Autoconfigures all necessary beans and seamlessly integrates with Spring's RestControllers and Jackson libraries.
The json mystique's spring boot starter autoconfigures the json mystique environment appropriately, creating all the necessary beans. Its primary features are
- Configures the simple Jackson Json Convertor as a bean
- Configures the simple Gson Json Convertor as a bean
- Configures Jackson Object Mapper with the ability to serialise and deserialise Gson Objects (JsonElement)
- Configures JsonMystique with its appropriate turns as a bean
- If Spring-web is in the classpath, it connfigures a RestTemplate with the ability to serialise and deserialise Gson Objects (JsonElement)
- Automatically registers custom Json Mystique
MystTurns
with JsonMystique
For more details refer the usage guide or the sample projects for usage
<dependency>
<groupId>com.balajeetm.mystique</groupId>
<artifactId>gson-utils</artifactId>
<version>2.5.3</version>
</dependency>
The json mystique gson utility library provides a set of utility classes to operate on manipulate, access and operate on
json objects. All the utilities are standalone instances that can be accessed via getInstance()
and use right
away.
The utility classes are
- Json Lever - Utility to operate on raw json objects. Exposes simplified lodash like object manipulation interfaces and a type safe use of the Gson library. Allows deep and shallow merge & clone of jsons
- Gson Convertor
- Utility for POJO Object Model Mapping. Provides a simplified interface to convert to and from a json
- Json Comparator
- Utility to compare two jsons
- Json Query - Utility to perform sql-like queries on a json element to select appropriate fields from a json (can be an object or an array)
- Json Builder - Builder utility to build jsons elements so that the properties can be added in a chained fashion
<dependency>
<groupId>com.balajeetm.mystique</groupId>
<artifactId>jackson-utils</artifactId>
<version>2.5.3</version>
</dependency>
The json mystique jackson utility library provides a set of utility classes, implemented using jackson, to operate on raw json objects and serialise deserialise POJOs. The utility classes are
- Jackson Convertor
- Utility for POJO Object Model Mapping
JsonMystique completely supports Spring Boot 2.
<dependency>
<groupId>com.balajeetm.mystique</groupId>
<artifactId>json-mystique</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.balajeetm.mystique</groupId>
<artifactId>json-mystique-starter</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.balajeetm.mystique</groupId>
<artifactId>gson-utils</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.balajeetm.mystique</groupId>
<artifactId>jackson-utils</artifactId>
<version>2.5.3</version>
</dependency>
For detailed documentation, refer the documentation index
For more information on the usage and detailed usage guides, refer the documentation home