as I new in jolt and next to the previous question I'm trying to add some more steps.
again from the input as this
{
"iban": "IR970130100000000000001399",
"paymentCode": "124"
}
I want to have such output
{
"parameters": [
{
"name": "P_IBAN",
"value": "IR970130100000000000001399"
},
{
"name": "P_PAYMENTCODE",
"value": "124"
},
{
"name": "P_RQID",
"value": "4f2ba174-690f-4d41-9bcc-b958789fe6d7"
},
{
"name": "P_TYPEX",
"value": "1"
},
{
"name": "P_BIC",
"value": "1"
}
],
"requestID": "RequestID",
"callType": "Reader",
"encoding": "ASCII"
}
the steps are as:
this is the spec I have
[
{
"operation": "default",
"spec": {
"parameters": {
"name": "P_RQUD",
"value": "4f2ba174-690f-4d41-9bcc-b958789fe6d7"
}
}
},
{
"operation": "shift",
"spec": {
"parameters": "&",
"*": {
"$": "parameters[#2].name",
"@": "parameters[#2].value"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"parameters": {
"*": {
"name": "=toUpper"
}
}
}
},
{
"operation": "default",
"spec": {
"callType": "Reader",
"encoding": "ASCII",
"requestID": "RequestID"
}
}
]
You can convert the first "parameter"
node to an array key while getting rid of the last default transformation spec, as enough to use #
prefixes on the LHS to generate fixed key-value pairs within a shift transformation spec such as
[
{
"operation": "default",
"spec": {
"parameters": [
{
"name": "RQUD",
"value": "4f2ba174-690f-4d41-9bcc-b958789fe6d7"
},
{
"name": "TYPEX",
"value": "1"
},
{
"name": "BIC",
"value": "1"
}
]
}
},
{
"operation": "shift",
"spec": {
"parameters": { "*": "&1" }, //&1 copies the literal value "parameters" after traversing 1 level above
"*": {
"$": "parameters[#2].name",
"@": "parameters[#2].value"
},
"#RequestID": "requestID",
"#Reader": "callType",
"#ASCII": "encoding"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"parameters": {
"*": {
"n": "=toUpper(@(1,name))",
"name": "=concat('P_',@(1,n))"
}
}
}
},
{ // get rid of the newly generated extra attribute
"operation": "remove",
"spec": {
"parameters": {
"*": {
"n": ""
}
}
}
},
{ // sorts the elements alphabetically as default
"operation": "sort"
}
]
the demo on the site http://jolt-demo.appspot.com/ is :