jsonjolt

Jolt transform for the object with the arrray


input payload is below and output should contain Others + an element from cloumn X. need a JOLT tranform for below

{
  "Others": {
    "eventTime": "2024-09-05T01:50:05.861",
    "groupArticleNumber": "IW6012",
    "groupModelNumber": "JSO42",
    "seasonCode": "20242",
    "productDescriptionEN": "WINDBREAKER",
    "subBrand": "2",
    "brand": "11",
    "productGroup": "26",
    "franchiseCode": "000",
    "businessSegment": "335",
    "salesLine": "839",
    "developmentType": "TN",
    "seasonState": "A",
    "articleCarriedOverFrom": null,
    "materialComposition": "100% PET-REC",
    "mainMaterialFlag": true,
    "productDescEN": "WINDBREAKER",
    "colorwayShortDescEN": "LEGTEA",
    "keyCategory": "00009",
    "ageGroup": "J",
    "gender": "U",
    "genderAge": "12",
    "genderAgeMain": "Kids",
    "articleLifeCycle": "50",
    "sizePage": "J4",
    "articleCreationSeason": "20242",
    "articleActiveSeason": "20242",
    "rmhProductDivision": "2",
    "rmhProductType": "40",
    "rmhCategory": "35",
    "retailClass": "22335",
    "retailSubClass": "2233540",
    "retailDepartment": "22",
    "retailSubDepartment": "223",
    "rmhGender": "3"
  },
  "x": [
    {
      "sourcingSizeCode3": "550"
    },
    {
      "sourcingSizeCode3": "540"
    },
    {
      "sourcingSizeCode3": "530"
    },
    {
      "sourcingSizeCode3": "520"
    },
    {
      "sourcingSizeCode3": "510"
    },
    {
      "sourcingSizeCode3": "500"
    },
    {
      "sourcingSizeCode3": "580"
    },
    {
      "sourcingSizeCode3": "570"
    },
    {
      "sourcingSizeCode3": "560"
    }
  ]
}

Ihave tried like multiplying the array but no luck it will be great. It seems like the current transformation is only extracting the sourcingSizeCode3 array and not merging it with the Others object as intended. To ensure that each sourcingSizeCode3 element is combined with the Others fields, a correct JOLT transformation should merge both parts.

expected output

[
  {
    "eventTime": "2024-09-05T01:50:05.861",
    "groupArticleNumber": "IW6012",
    "groupModelNumber": "JSO42",
    "seasonCode": "20242",
    "productDescriptionEN": "WINDBREAKER",
    "subBrand": "2",
    "brand": "11",
    "productGroup": "26",
    "franchiseCode": "000",
    "businessSegment": "335",
    "salesLine": "839",
    "developmentType": "TN",
    "seasonState": "A",
    "articleCarriedOverFrom": null,
    "materialComposition": "100% PET-REC",
    "mainMaterialFlag": true,
    "productDescEN": "WINDBREAKER",
    "colorwayShortDescEN": "LEGTEA",
    "keyCategory": "00009",
    "ageGroup": "J",
    "gender": "U",
    "genderAge": "12",
    "genderAgeMain": "Kids",
    "articleLifeCycle": "50",
    "sizePage": "J4",
    "articleCreationSeason": "20242",
    "articleActiveSeason": "20242",
    "rmhProductDivision": "2",
    "rmhProductType": "40",
    "rmhCategory": "35",
    "retailClass": "22335",
    "retailSubClass": "2233540",
    "retailDepartment": "22",
    "retailSubDepartment": "223",
    "rmhGender": "3",
    "sourcingSizeCode3": "550"
  },
  {
    "eventTime": "2024-09-05T01:50:05.861",
    "groupArticleNumber": "IW6012",
    "groupModelNumber": "JSO42",
    "seasonCode": "20242",
    "productDescriptionEN": "WINDBREAKER",
    "subBrand": "2",
    "brand": "11",
    "productGroup": "26",
    "franchiseCode": "000",
    "businessSegment": "335",
    "salesLine": "839",
    "developmentType": "TN",
    "seasonState": "A",
    "articleCarriedOverFrom": null,
    "materialComposition": "100% PET-REC",
    "mainMaterialFlag": true,
    "productDescEN": "WINDBREAKER",
    "colorwayShortDescEN": "LEGTEA",
    "keyCategory": "00009",
    "ageGroup": "J",
    "gender": "U",
    "genderAge": "12",
    "genderAgeMain": "Kids",
    "articleLifeCycle": "50",
    "sizePage": "J4",
    "articleCreationSeason": "20242",
    "articleActiveSeason": "20242",
    "rmhProductDivision": "2",
    "rmhProductType": "40",
    "rmhCategory": "35",
    "retailClass": "22335",
    "retailSubClass": "2233540",
    "retailDepartment": "22",
    "retailSubDepartment": "223",
    "rmhGender": "3",
    "sourcingSizeCode3": "540"
  },
  {
    "eventTime": "2024-09-05T01:50:05.861",
    "groupArticleNumber": "IW6012",
    "groupModelNumber": "JSO42",
    "seasonCode": "20242",
    "productDescriptionEN": "WINDBREAKER",
    "subBrand": "2",
    "brand": "11",
    "productGroup": "26",
    "franchiseCode": "000",
    "businessSegment": "335",
    "salesLine": "839",
    "developmentType": "TN",
    "seasonState": "A",
    "articleCarriedOverFrom": null,
    "materialComposition": "100% PET-REC",
    "mainMaterialFlag": true,
    "productDescEN": "WINDBREAKER",
    "colorwayShortDescEN": "LEGTEA",
    "keyCategory": "00009",
    "ageGroup": "J",
    "gender": "U",
    "genderAge": "12",
    "genderAgeMain": "Kids",
    "articleLifeCycle": "50",
    "sizePage": "J4",
    "articleCreationSeason": "20242",
    "articleActiveSeason": "20242",
    "rmhProductDivision": "2",
    "rmhProductType": "40",
    "rmhCategory": "35",
    "retailClass": "22335",
    "retailSubClass": "2233540",
    "retailDepartment": "22",
    "retailSubDepartment": "223",
    "rmhGender": "3",
    "sourcingSizeCode3": "530"
  }
  // Similar objects for other sourcingSizeCode3 values
]

Solution

  • You just can loop through the x array while bringing the Others object as a whole in such a way that

    [
      {
        "operation": "shift",
        "spec": {
          "x": {
            "*": {
              "@2,Others": { "*": "[&1].&" }, // go two levels up the tree to grab the values of the "Others" object
              "*": "[&1].&"
            }
          }
        }
      }
    ]
    

    A minimalist demo on https://jolt-demo.appspot.com/ follows :

    enter image description here