I am looking for the jolt specs to split the treefield string value to a list of JSON objects in below mentioned format.
Could someone help me with the jolt specs to convert the below mentioned input to the output
Input
[
{
"A": "value1",
"B": "value2",
"C": {
"D": "x1",
"E": {
"treefield": "k1-value1#k2-value2"
},
"F": {
"a": "x1",
"x": {
"y": 1
}
},
"H": "x4"
}
}
]
Output
[
{
"A": "value1",
"B": "value2",
"C": {
"D": "x1",
"E": {
"treefield": [
{
"paramid": "k1",
"paramvalue": {
"string": "value1"
}
},
{
"paramid": "k2",
"paramvalue": {
"string": "value2"
}
}
]
},
"F": {
"a": "x1",
"x": {
"y": 1
}
},
"H": "x4"
}
}
]
You can apply modify-overwrite-beta transformations successively along with split function in order to seperate the concerned string by # and - characters, and then use shift transformation to shape as desired such as
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"C": {
"E": {
"*": "=split('#',@(1,&))"
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"C": {
"E": {
"*": "=split('-',@(1,&))"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "&",
"C": {
"*": "&1.&",
"E": {
"*": {
"*": {
"0": "&4.&3.&2.[&1].paramid",
"1": "&4.&3.&2.[&1].paramvalue.string"
}
}
}
}
}
}
}
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With