Home > OS >  Jolt spec is working for most cases but not for some nested array
Jolt spec is working for most cases but not for some nested array

Time:10-20

My jolt spec is working for most of the scenarios, but when there is different elements in the nested arrays, we are getting one Extra null. Can we correct that

I am new to nifi. I was trying to create a jolt spec but not getting it. Could anyone please help me. Details as below: The Attributes in flow file

[
  {
    "PC9Code": "678990-0000",
    "ProductDescription": "94520 STANDARD SHORT STEEL BLACK ADV SHO",
    "MaterialType": "Finished Goods",
    "ProductType": "REGULAR",
    "Brand": "LEVIS",
    "ProductCategory": "BOTTOMS",
    "ConsumerGroup": "MEN",
    "Gender": "MALE",
    "CapsuleName": "0",
    "FFCCode": "X3209",
    "FFCName": "STEEL BLACK ADV SHORT",
    "StyleCode": "94520",
    "StyleName": "94520 STANDARD SHORT",
    "ProductLine": "Levi's Mainline",
    "ProductSubCategory": "SHORTS",
    "ProductClass": "SHORTS",
    "ProductSubClass": "MID LENGTH SHORTS",
    "CarryOver": "N",
    "ProductPricePositioningDesc": "TIER 3",
    "AgilityIndicator": "N",
    "OriginalBFF": "0",
    "ProductLifeCycle": "SEASONAL",
    "ColorCode": "X3209",
    "ColorName": "STEEL BLACK ADV SHOR",
    "EarlyDelivery": "NO",
    "FirstOnFloorMonth": "1",
    "GlobalPlanningView": "0",
    "UOM": "EA",
    "PC13": [
      {
        "SKU": "00501000030399999210",
        "DIM1": "3078",
        "DIM2": "3079"
      }
    ],
    "OperationType": "UPDATE",
    "TimeStamp": "6/2/2022  4:52:17 PM"
  },
  {
    "PC9Code": "12385-0000",
    "ProductDescription": "94520 STANDARD SHORT STEEL BLACK ADV SHO",
    "MaterialType": "Finished Goods",
    "ProductType": "REGULAR",
    "Brand": "LEVIS",
    "ProductCategory": "BOTTOMS",
    "ConsumerGroup": "MEN",
    "Gender": "MALE",
    "CapsuleName": "0",
    "FFCCode": "X3209",
    "FFCName": "STEEL BLACK ADV SHORT",
    "StyleCode": "94520",
    "StyleName": "94520 STANDARD SHORT",
    "ProductLine": "Levi's Mainline",
    "ProductSubCategory": "SHORTS",
    "ProductClass": "SHORTS",
    "ProductSubClass": "MID LENGTH SHORTS",
    "CarryOver": "N",
    "ProductPricePositioningDesc": "TIER 3",
    "AgilityIndicator": "N",
    "OriginalBFF": "0",
    "ProductLifeCycle": "SEASONAL",
    "ColorCode": "X3209",
    "ColorName": "STEEL BLACK ADV SHOR",
    "EarlyDelivery": "NO",
    "FirstOnFloorMonth": "1",
    "GlobalPlanningView": "0",
    "UOM": "EA",
    "PC13": [
      {
        "SKU": "0050100003030",
        "DIM1": "30",
        "DIM2": "30"
      },
      {
        "SKU": "00501000030301221",
        "DIM1": "310",
        "DIM2": "3023"
      }
    ],
    "OperationType": "UPDATE",
    "TimeStamp": "6/2/2022  4:52:17 PM"
  }
]

Current Jolt Spec

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "PC13": {
          "*": {
            "@": "&[&3]",
            "@(2,AgilityIndicator)": "&[&3].AgilityIndicator",
            "@(2,Brand)": "&[&3].Brand",
            "@(2,CapsuleName)": "&[&3].CapsuleName",
            "@(2,CarryOver)": "&[&3].CarryOver",
            "@(2,ColorCode)": "&[&3].ColorCode",
            "@(2,ColorName)": "&[&3].ColorName",
            "@(2,ConsumerGroup)": "&[&3].ConsumerGroup",
            "@(2,EarlyDelivery)": "&[&3].EarlyDelivery",
            "@(2,FFCCode)": "&[&3].FFCCode",
            "@(2,FFCName)": "&[&3].FFCName",
            "@(2,FirstOnFloorMonth)": "&[&3].FirstOnFloorMonth",
            "@(2,Gender)": "&[&3].Gender",
            "@(2,GlobalPlanningView)": "&[&3].GlobalPlanningView",
            "@(2,MaterialType)": "&[&3].MaterialType",
            "@(2,OperationType)": "&[&3].OperationType",
            "@(2,OriginalBFF)": "&[&3].OriginalBFF",
            "@(2,PC9Code)": "&[&3].PC9Code",
            "@(2,ProductCategory)": "&[&3].ProductCategory",
            "@(2,ProductClass)": "&[&3].ProductClass",
            "@(2,ProductDescription)": "&[&3].ProductDescription",
            "@(2,ProductLifeCycle)": "&[&3].ProductLifeCycle",
            "@(2,ProductLine)": "&[&3].ProductLine",
            "@(2,ProductPricePositioningDesc)": "&[&3].ProductPricePositioningDesc",
            "@(2,ProductSubCategory)": "&[&3].ProductSubCategory",
            "@(2,ProductSubClass)": "&[&3].ProductSubClass",
            "@(2,ProductType)": "&[&3].ProductType",
            "@(2,StyleCode)": "&[&3].StyleCode",
            "@(2,StyleName)": "&[&3].StyleName",
            "@(2,TimeStamp)": "&[&3].TimeStamp",
            "@(2,UOM)": "&[&3].UOM"
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&1.&"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": ""
      }
    }
  }
]

The Image Of Current Output

Having one null inbetween the elements

enter image description here

CodePudding user response:

You can add two more transformations to the current spec such as

[
  <the current spec>,
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": "&2.&1.&" // separate each object levels
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": ""
      }
    }
  }
]

in which occuring one level deeper shift removes the non-objects

  • Related