Reputation: 41
I am trying remove a field from array of JSON using JOLT Transformation. below is the input JSON and expected output JSON.
can you suggest the JOLT transformation for the mentioned scenario
Input:
{
"code": 200,
"data": {
"totalCount": 1,
"SCount": 1,
"FCount": 0,
"FSequences": [],
"token": [
328358
]
},
"id": "ce27g26hvamob9lbd0eg"
}
Jolt I'm using:
[
{
"operation": "shift",
"spec": {
"data": {
"*": "&"
},
"status|id": "&"
}
}
]
Expected output:
{
"totalCount" : 1,
"SCount" : 1,
"FCount" : 0,
"FSequences" : "",
"token" : "328358",
"status" : 200,
"id" : "ce27g26hvamob9lbd0eg"
}
Upvotes: 1
Views: 47
Reputation: 65323
You can consecutively apply shift and modify specs such that
[
{
"operation": "shift",
"spec": {
"data": {
"*": "&",
"token": {
"*": "&1" // replicates the tag "token" by grabbing after going up tree one level
}
},
"code": "status", // renaming the attribute
"id": "&"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*u*n*": ["=toInteger", ""], // conversion only doesn't apply for "FSequences" among *u*n* tagged attributes
"*o*n": "=toString" // only applied for "token" attribute
}
}
]
Upvotes: 1