Search code examples
jsonjolt

Jolt transform operation where we need to filter on data


we want to filter all those records where "articleActiveSeason" is not equal to modelActiveSeason

input payload


[ {
  "eventTime" : "2024-01-17T15:10:06.858",
  "groupArticleNumber" : "FT6559",
  "groupModelNumber" : "FRX88",
  "productDescriptionEN" : "ESTRO 19 JSYY",
  "subBrand" : "1",
  "brand" : "11",
  "businessSegment" : "104",
  "modelActiveSeason" : "20251",
  "salesLine" : "L84",
  "productDescEN" : "ESTRO 19 JSYY",
  "colorwayShortDescEN" : "TMLGBL/WHITE",
  "keyCategory" : "00095",
  "ageGroup" : "J",
  "gender" : "M",
  "genderAge" : "16",
  "genderAgeMain" : "Kids",
  "articleLifeCycle" : "50",
  "sizePage" : "J4",
  "articleCreationSeason" : "20201",
  "articleActiveSeason" : "20242",
  "rmhProductDivision" : "2",
  "rmhProductType" : "30",
  "rmhCategory" : "09",
  "retailClass" : "12309",
  "retailSubClass" : "1230930",
  "retailDepartment" : "12",
  "retailSubDepartment" : "123",
  "materialComposition" : "100% PET-REC",
  "mainMaterialFlag" : true,
  "sourcingSizeCode3" : "190"
}, {
  "eventTime" : "2024-01-17T15:10:06.858",
  "groupArticleNumber" : "FT6559",
  "groupModelNumber" : "FRX88",
  "productDescriptionEN" : "ESTRO 19 JSYY",
  "subBrand" : "1",
  "brand" : "11",
  "businessSegment" : "104",
  "modelActiveSeason" : "20251",
  "salesLine" : "L84",
  "productDescEN" : "ESTRO 19 JSYY",
  "colorwayShortDescEN" : "TMLGBL/WHITE",
  "keyCategory" : "00095",
  "ageGroup" : "J",
  "gender" : "M",
  "genderAge" : "16",
  "genderAgeMain" : "Kids",
  "articleLifeCycle" : "50",
  "sizePage" : "J4",
  "articleCreationSeason" : "20201",
  "articleActiveSeason" : "20242",
  "rmhProductDivision" : "2",
  "rmhProductType" : "30",
  "rmhCategory" : "09",
  "retailClass" : "12309",
  "retailSubClass" : "1230930",
  "retailDepartment" : "12",
  "retailSubDepartment" : "123",
  "materialComposition" : "100% PET-DAT",
  "mainMaterialFlag" : false,
  "sourcingSizeCode3" : "190"
}, {
  "eventTime" : "2024-01-17T15:10:06.858",
  "groupArticleNumber" : "FT6559",
  "groupModelNumber" : "FRX88",
  "productDescriptionEN" : "ESTRO 19 JSYY",
  "subBrand" : "1",
  "brand" : "11",
  "businessSegment" : "104",
  "modelActiveSeason" : "20251",
  "salesLine" : "L84",
  "productDescEN" : "ESTRO 19 JSYY",
  "colorwayShortDescEN" : "TMLGBL/WHITE",
  "keyCategory" : "00095",
  "ageGroup" : "J",
  "gender" : "M",
  "genderAge" : "16",
  "genderAgeMain" : "Kids",
  "articleLifeCycle" : "50",
  "sizePage" : "J4",
  "articleCreationSeason" : "20201",
  "articleActiveSeason" : "20242",
  "rmhProductDivision" : "2",
  "rmhProductType" : "30",
  "rmhCategory" : "09",
  "retailClass" : "12309",
  "retailSubClass" : "1230930",
  "retailDepartment" : "12",
  "retailSubDepartment" : "123",
  "materialComposition" : "100% PET-REC",
  "mainMaterialFlag" : true,
  "sourcingSizeCode3" : "180"
}, {
  "eventTime" : "2024-01-17T15:10:06.858",
  "groupArticleNumber" : "FT6559",
  "groupModelNumber" : "FRX88",
  "productDescriptionEN" : "ESTRO 19 JSYY",
  "subBrand" : "1",
  "brand" : "11",
  "businessSegment" : "104",
  "modelActiveSeason" : "20251",
  "salesLine" : "L84",
  "productDescEN" : "ESTRO 19 JSYY",
  "colorwayShortDescEN" : "TMLGBL/WHITE",
  "keyCategory" : "00095",
  "ageGroup" : "J",
  "gender" : "M",
  "genderAge" : "16",
  "genderAgeMain" : "Kids",
  "articleLifeCycle" : "50",
  "sizePage" : "J4",
  "articleCreationSeason" : "20201",
  "articleActiveSeason" : "20242",
  "rmhProductDivision" : "2",
  "rmhProductType" : "30",
  "rmhCategory" : "09",
  "retailClass" : "12309",
  "retailSubClass" : "1230930",
  "retailDepartment" : "12",
  "retailSubDepartment" : "123",
  "materialComposition" : "100% PET-DAT",
  "mainMaterialFlag" : false,
  "sourcingSizeCode3" : "180"
} ]

we need to add filter operation using jolt

Can we apply filter in jolt expression itself? we want to filter all those records where "articleActiveSeason" is not equal to modelActiveSeason


Solution

  • You can use the following transformation specs in order to compare and non-match by those attributes:

    [
      { // partition the objects by both of those values
        "operation": "shift",
        "spec": {
          "*": {
            "@": "@1,modelActiveSeason.@1,articleActiveSeason.&1"
          }
        }
      },
      {
        "operation": "shift",
        "spec": {
          "*": {
            "&": { // matching ones
              "*": {
                "": ""
              }
            },
            "*": { // non-matching ones
              "*": {
                "@": "[]"
              }
            }
          }
        }
      }
    ]