Reputation: 3
I am trying to do a JOLT shift transformation of an inputted JSON-list Below my input:
[
{
"number": 1001,
"description": "KA01"
},
{
"number": 1002,
"description": "KA02"
}
]
And I want to create this output:
{
"actions" : [
{
"_type": "SetFieldValue",
"fieldName": "UUID",
"value": "uuid"
},
{ "_type": "InsertRow" },
{
"_type": "SetFieldValue",
"fieldName": "number",
"value": "1001"
},
{
"_type": "SetFieldValue",
"fieldName": "description",
"value": "KA01"
},
{ "_type": "InsertRow" },
{
"_type": "SetFieldValue",
"fieldName": "number",
"value": "1002"
},
{
"_type": "SetFieldValue",
"fieldName": "description",
"value": "KA02"
},
{
"_type": "SetFieldValue",
"fieldName": "start"
}
]
}
I haven´t done much with JOLT transformation and need help in this case.
Upvotes: 0
Views: 128
Reputation: 65408
First of all you can divide the JSON value into parts by key names and values, and then add _type
attributes as being default such as
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"$": "&1.[&2].fieldName",
"@": "&1.[&2].value"
}
},
"#UUID": "x[#2].fieldName",
"#uuid": "x[#2].value",
"#start": "y[#2].fieldName"
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": ""
}
}
},
{
"operation": "default",
"spec": {
"*": {
"_type": "SetFieldValue"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"@": ""
},
"#InsertRow": "_type"
}
},
{
"operation": "sort",
"spec": {}
}
]
Upvotes: 0