Hi I’am trying a jolt transform of below
{
"Others": {
"eventTime": "2024-09-05T01:50:05.861",
"groupArticleNumber": "IW6012",
"groupModelNumber": "JSO42",
"seasonCode": "20242"
},
"x": [
{
"materialComposition": "100% PET-REC",
"mainMaterialFlag": true
}
],
"y": [
{
"sourcingSizeCode3": "550"
},
{
"sourcingSizeCode3": "540"
}
]
}
and the expected output as
[
{
"eventTime": "2024-09-05T01:50:05.861",
"groupArticleNumber": "IW6012",
"groupModelNumber": "JSO42",
"seasonCode": "20242",
"materialComposition": "100% PET-REC",
"mainMaterialFlag": true,
"sourcingSizeCode3": "550"
},
{
"eventTime": "2024-09-05T01:50:05.861",
"groupArticleNumber": "IW6012",
"groupModelNumber": "JSO42",
"seasonCode": "20242",
"materialComposition": "100% PET-REC",
"mainMaterialFlag": true,
"sourcingSizeCode3": "540"
}
]
I need a jolt spec for same. I have tried so many spec trying multplexing aslo but no luck.
Hi hope this spec helps you resolve your query.
[
{
"operation": "shift",
"spec": {
"y": {
"*": {
"sourcingSizeCode3": "[#2].sourcingSizeCode3",
"@(2,Others)": {
"*": "[#3].&"
},
"@(2,x)": {
"*": {
"*": "[#4].&"
}
}
}
}
}
}
]
1
It’s kind of an extension of this former question ” #75451057 ” :
Loop through the array of objects with highest numbe of objects, namely “y” while transferring whole content of “Others” object and “x” array inside such as
[
{
"operation": "shift",
"spec": {
"y": {
"*": {
"@2,Others": { "*": "[&1].&" }, // go two levels up the tree to grab the values of the "Others" object
"@2,x": { "*": { "*": "[&2].&" } },// walk through all deepest elements of "x" array
"*": "[&1].&" //get all key-value pairs within the objects under the "y" array
}
}
}
}
]
OR
[
{
"operation": "shift",
"spec": {
"y": {
"*": {
"@2,Others|@2,x[0]": {//directly pass content for the zeroth index of the x array
"*": "[&1].&"
} ,
"*": "[&1].&" //get all key-value pairs within the objects under the "y" array
}
}
}
}
]
Edit ( for the new case ) :
You stated whether the input is this one :
{
"Others": {
"eventTime": "2024-09-05T01:50:05.861",
"groupArticleNumber": "IW6012",
"groupModelNumber": "JSO42",
"seasonCode": "20242"
},
"x": [
{
"materialComposition": "100% PET-REC",
"mainMaterialFlag": true
},
{
"materialComposition": "100% PET-REC-123",
"mainMaterialFlag": false
}
],
"y": [
{
"sourcingSizeCode3": "550"
},
{
"sourcingSizeCode3": "540"
}
]
}
then replace @2,x[0] with @2,x[&] , which looks for the dynamic index by the ampersand, within the second provided option such as
[
{
"operation": "shift",
"spec": {
"y": {
"*": {
"@2,Others|@2,x[&]": { //directly pass content for the zeroth index of the x array
"*": "[&1].&"
},
"*": "[&1].&" //get all key-value pairs within the objects under the "y" array
}
}
}
}
]
2