Can someone give a brief explanation of different functions in the JOLT transformation library for JSON to JSON transformations?
A brief explanation of JOLT function.
- Like :- Function name - what it does -- its arguments
Can someone give a brief explanation of different functions in the JOLT transformation library for JSON to JSON transformations?
A brief explanation of JOLT function.
Here is example of each function
JSON input
{
"STRING": {
"product": "Product A",
"company": "company a",
"value": "100",
"measureWithSpaces": " 10 meters "
},
"NUMBER": {
"array": [ 3, 5, 2, 7, 1 ],
"negativeValue": -100,
"positiveValue": 50
},
"TYPE": {
"value": 10.5,
"stringBoolean": "true",
"objectWithNull": {
"fielWithValue": "ABC",
"nullField": null
}
},
"LIST": {
"array": [ "c", "t", "m", "a" ],
"stringField": "123"
}
}
Jolt Specification
[
{
"operation": "modify-overwrite-beta",
"spec": {
"STRING": {
"product": "=toLower(@(1,product))",
"company": "=toUpper(@(1,company))",
"product_company": "=concat(@(1,product),'_',@(1,company))",
"joinProductCompany": "=join(' - ',@(1,product),@(1,company))",
"splitProductCompany": "=split('[-]',@(1,joinProductCompany))",
"substringProduct": "=substring(@(1,product),0,4)",
"value": "=leftPad(@(1,value),6,'A')",
"measure": "=trim(@(1,measureWithSpaces))"
},
"NUMBER": {
"minArray": "=min(@(1,array))",
"maxArray": "=max(@(1,array))",
"absoluteValue": "=abs(@(1,negativeValue))",
"averageArray": "=avg(@(1,array))",
"sumArray": "=intSum(@(1,array))",
"subtrArray": "=intSubtract(@(1,positiveValue), 20)",
"division": "=divide(@(1,positiveValue),2)",
"divisionRound": "=divideAndRound(3,@(1,positiveValue),3)"
},
"TYPE": {
"integerValue": "=toInteger(@(1,value))",
"booleano": "=toBoolean(@(1,stringBoolean))",
"stringValue": "=toString(@(1,value))",
"stringBoolean": "=size",
"objectWithNull": "=recursivelySquashNulls"
},
"LIST": {
"arrayFirstItem": "=firstElement(@(1,array))",
"arrayLastItem": "=lastElement(@(1,array))",
"arrayElement": "=elementAt(@(1,array),2)",
"fieldToList": "=toList(@(1,stringField))",
"orderedArray": "=sort(@(1,array))"
}
}
}
]
JSON output
{
"STRING": {
"product": "product a",
"company": "COMPANY A",
"value": "AAA100",
"measureWithSpaces": " 10 meters ",
"product_company": "product a_COMPANY A",
"joinProductCompany": "product a - COMPANY A",
"splitProductCompany": [
"product a ",
" COMPANY A"
],
"substringProduct": "prod",
"measure": "10 meters"
},
"NUMBER": {
"array": [ 3, 5, 2, 7, 1 ],
"negativeValue": -100,
"positiveValue": 50,
"minArray": 1,
"maxArray": 7,
"absoluteValue": 100,
"averageArray": 3.6,
"sumArray": 18,
"subtrArray": 30,
"division": 25,
"divisionRound": 16.667
},
"TYPE": {
"value": 10.5,
"stringBoolean": 4,
"objectWithNull": {
"fielWithValue": "ABC"
},
"integerValue": 10,
"booleano": true,
"stringValue": "10.5"
},
"LIST": {
"array": [
"c",
"t",
"m",
"a"
],
"stringField": "123",
"arrayFirstItem": "c",
"arrayLastItem": "a",
"fieldToList": [
"123"
],
"orderedArray": [ "a", "c", "m", "t" ]
}
}