I have a JSON data structure that contains a data object. Inside the data object, there is a code field and a body array. Now, I would like to add the value of the code field to each element of the body array. Specifically, the value of code should be included along with the other fields of each object in the body array. How can I achieve this transformation using the Jolt tool?
Here is my input data:
{
"data": {
"code": "Xd001",
"body": [
{
"id": "1",
"name": "ls"
},
{
"id": "2",
"name": "zs"
}
]
}
}
I want the output to look like this:
{
"data": {
"body": [
{
"id": "1",
"name": "ls",
"code": "Xd001"
},
{
"id": "2",
"name": "zs",
"code": "Xd001"
}
]
}
}
I have a JSON data structure that contains a data object. Inside the data object, there is a code field and a body array. Now, I would like to add the value of the code field to each element of the body array. Specifically, the value of code should be included along with the other fields of each object in the body array. How can I achieve this transformation using the Jolt tool?
Here is my input data:
{
"data": {
"code": "Xd001",
"body": [
{
"id": "1",
"name": "ls"
},
{
"id": "2",
"name": "zs"
}
]
}
}
I want the output to look like this:
{
"data": {
"body": [
{
"id": "1",
"name": "ls",
"code": "Xd001"
},
{
"id": "2",
"name": "zs",
"code": "Xd001"
}
]
}
}