I’d like to replace a value in a json with JOLT but I haven’t managed to do so.
My JSON :
{
"MIRecord": [
{
"RowIndex": "0",
"NameValue": [
{
"Name": "MBWHLO",
"Value": "123"
},
{
"Name": "MBITNO",
"Value": "123"
},
{
"Name": "V_NETA",
"Value": "123"
}
]
},
{
"RowIndex": "1",
"NameValue": [
{
"Name": "MBWHLO",
"Value": "123"
},
{
"Name": "MBITNO",
"Value": "123"
},
{
"Name": "V_NETA",
"Value": "123"
}
]
}
]
}
I want to replace :
MBWHLO
toCHANGE1
MBITNO
toCHANGE2
V_NETA
toCHANGE3
My target JSON :
{
"MIRecord": [
{
"RowIndex": "0",
"NameValue": [
{
"Name": "CHANGE1",
"Value": "123"
},
{
"Name": "CHANGE2",
"Value": "123"
},
{
"Name": "CHANGE3",
"Value": "123"
}
]
},
{
"RowIndex": "1",
"NameValue": [
{
"Name": "CHANGE1",
"Value": "123"
},
{
"Name": "CHANGE2",
"Value": "123"
},
{
"Name": "CHANGE13",
"Value": "123"
}
]
}
]
}
I try this but i change all of "Name" value to CHANGE1
[
{
"operation": "modify-overwrite-beta",
"spec": {
"MIRecord": {
"*": {
"NameValue": {
"*": {
"Name": "CHANGE1"
}
}
}
}
}
}
]
I don’t know if I’m using the right function to replace or if I need to rebuild the whole json. But I’d like to avoid having to redo the json because the input JSON isn’t static.
Does anyone have a solution please?
2
Answers
here's my screenshot, where you can see that the JOLT isn't working as expected
To replace the values of MBWHLO, MBITNO, and V_NETA in your JSON with CHANGE1, CHANGE2, and CHANGE3, respectively, you can use the following Jolt transformation:
This transformation will use the modify-overwrite-beta operation to overwrite the values of the Name fields for the MBWHLO, MBITNO, and V_NETA fields with the corresponding values of CHANGE1, CHANGE2, and CHANGE3.
For example, if you apply this transformation to your input JSON, you will get the following output JSON:
You can use this Jolt transformation to replace the values of MBWHLO, MBITNO, and V_NETA in your JSON without having to rebuild the entire JSON.