Skip to content

How to map data.code to each element in the body array using Jolt? #1273

Description

@XyhVeryNB

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"
}
]
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions