I want to move "id" field to each of element in "user_roles" field of the document below.
I used the spec below but it didn’t work as my expected, I’m not sure where I may have made an error in the JOLT specification.
Input:
{
"id": "657a9dc588b19",
"user_roles": [
{
"role": 2,
"status": 1,
"is_owner": true,
},
{
"role": 5,
"status": 1,
"is_owner": true,
},
{
"role": 3,
"status": 1,
"is_owner": true,
}
]
}
Spec:
[
{
"operation": "shift",
"spec": {
"user_roles": {
"*": {
"_id": "user_roles[&0]._id",
"*": "user_roles[&1].&"
}
}
}
}
]
Expect result:
{
"user_roles": [
{
"id": "657a9dc588b19",
"role": 2,
"status": 1,
"is_owner": true,
},
{
"id": "657a9dc588b19",
"role": 5,
"status": 1,
"is_owner": true,
},
{
"id": "657a9dc588b19",
"role": 3,
"status": 1,
"is_owner": true
}
]
}
2
Answers
You can use the spec below with just a minor change in your spec.
There is one more way to achieve the expected output.