vertx-jolt

This is a json to json transformation tool for vert.x. It use original com.bazaarvoice.jolt:jolt as a proxy.

License

License

Categories

Categories

Jolt Data JSON
GroupId

GroupId

com.github.lusoalex
ArtifactId

ArtifactId

vertx-jolt
Last Version

Last Version

0.2
Release Date

Release Date

Type

Type

jar
Description

Description

vertx-jolt
This is a json to json transformation tool for vert.x. It use original com.bazaarvoice.jolt:jolt as a proxy.
Project URL

Project URL

https://github.com/lusoalex/vertx-jolt
Source Code Management

Source Code Management

https://github.com/lusoalex/vertx-jolt

Download vertx-jolt

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.lusoalex/vertx-jolt/ -->
<dependency>
    <groupId>com.github.lusoalex</groupId>
    <artifactId>vertx-jolt</artifactId>
    <version>0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.lusoalex/vertx-jolt/
implementation 'com.github.lusoalex:vertx-jolt:0.2'
// https://jarcasting.com/artifacts/com.github.lusoalex/vertx-jolt/
implementation ("com.github.lusoalex:vertx-jolt:0.2")
'com.github.lusoalex:vertx-jolt:jar:0.2'
<dependency org="com.github.lusoalex" name="vertx-jolt" rev="0.2">
  <artifact name="vertx-jolt" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.lusoalex', module='vertx-jolt', version='0.2')
)
libraryDependencies += "com.github.lusoalex" % "vertx-jolt" % "0.2"
[com.github.lusoalex/vertx-jolt "0.2"]

Dependencies

compile (2)

Group / Artifact Type Version
io.vertx : vertx-core jar 3.3.3
com.bazaarvoice.jolt : jolt-core jar 0.0.24

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
com.bazaarvoice.jolt : json-utils jar 0.0.24

Project Modules

There are no modules declared in this project.

vertx-jolt

This project is a simple facade to original jolt project : https://github.com/bazaarvoice/jolt. JOLT project is a json to json transformation tool.

It works like a proxy to original jolt objects, by providing exactly the same class names & methods, but requiring Vert.x JsonObject instead of Map <String,Object>

That way we do not need to perform transformation in our business code.

Without vertx-jolt :


JsonArray joltJsonSpecs = this.readJsonToJsonSettings();
Chainr chainedRules = new ChainrBuilder(joltJsonSpecs.getList()).build();
Map <String,Object> transformedResult = (Map <String,Object>) chainedRules.transform(originalJson.toMap());
return new JsonObject(transformedResult);

Wit vertx-jolt :


JsonArray joltJsonSpecs = this.readJsonToJsonSettings();
Chainr chainedRules = new ChainrBuilder(joltJsonSpecs).build();
JsonObject transformedResult = chainedRules.transform(originalJson);
return transformedResult;

Here we will take as example an input JSON to transform (originalJson input above) :

{
	"content": [
		{
			"name": "Elysee",
			"country": "FRANCE",
			"address": "Avenue des Champs-Élysées",
			"city": "PARIS",
			"stores_id": 1,
			"zip_code": "75000",
			"gps_x": "48.869729",
			"gps_y": "2.307784",
			"phone_number": "+33 1 00 00 00 00",
			"backend_url": "https://north-europe.company.com/"
		},
		{
			"name": "Belem",
			"country": "PORTUGAL",
			"address": "Avenida Brasilia",
			"city": "LISBON",
			"stores_id": 2,
			"zip_code": "75000",
			"gps_x": "38.693060",
			"gps_y": "-9.218120",
			"phone_number": "+351 000 000 000",
			"backend_url": "https://south-europe.company.com/"
		},
		{
			"name": "Yu garden",
			"country": "CHINA",
			"address": "huanpu qu",
			"city": "Shanghai",
			"stores_id": 3,
			"zip_code": "XXXX",
			"gps_x": "31.227208",
			"gps_y": "121.491836",
			"phone_number": "+86 000 000 000",
			"backend_url": "https://south-asia.company.com/"
		}
	]
}

And the expected JSON result is a key value json (kind of UDDI) :

[ 
  {
    "key" : 1,
    "value" : "https://north-europe.company.com/"
  }, 
  {
    "key" : 2,
    "value" : "https://south-europe.company.com/"
  }, 
  {
    "key" : 3,
    "value" : "https://south-asia.company.com/"
  } 
]

To Achieve this, we need to provide a JOLT JSON specification, in our case it will be :

[
  {
    "operation": "shift",
    "spec": {
      "content": {
        "*": {
          "stores_id": "[&1].key",
          "backend_url": "[&1].value"
        }
      }
    }
  }
]

Versions

Version
0.2
0.1