0
votes

I'm new to JOLT, I'm facing some issue in getting the proper JSON after the jolt sepc transformation. Below are the given json, used Jolt Spec and expected output. But when I process the Jolt Spec I'm not getting ReportedQtyUom and ReportedQty data in the JSON output. Please anyone let me know where I'm going wrong. Thank You

Given JSON

[
  {
    "MaterialId": "na-103437",
    "LocationId": "0TB9",
    "OHReportingDate": "2020-08-18T20:57:16Z",
    "TankNumber": "KTLA",
    "stocks": [
      {
        "stockStatus": "OnHand",
        "quantity": [
          {
            "uom": "KG",
            "amount": "0.000",
            "ISOUom": "KGM"
          }
        ]
      },
      {
        "stockStatus": "Damaged",
        "quantity": [
          {
            "uom": "KG",
            "amount": "0.000",
            "ISOUom": "KGM"
          }
        ]
      },
      {
        "stockStatus": "QualityInspection",
        "quantity": [
          {
            "uom": "KG",
            "amount": "0.000",
            "ISOUom": "KGM"
          }
        ]
      }
    ]
  },
  {
    "MaterialId": "na-103437",
    "LocationId": "0TB9",
    "OHReportingDate": "2020-08-18T20:57:16Z",
    "TankNumber": "KTLJ",
    "stocks": [
      {
        "stockStatus": "OnHand",
        "quantity": [
          {
            "uom": "KG",
            "amount": "0.000",
            "ISOUom": "KGM"
          }
        ]
      },
      {
        "stockStatus": "Damaged",
        "quantity": [
          {
            "uom": "KG",
            "amount": "0.000",
            "ISOUom": "KGM"
          }
        ]
      },
      {
        "stockStatus": "QualityInspection",
        "quantity": [
          {
            "uom": "KG",
            "amount": "0.000",
            "ISOUom": "KGM"
          }
        ]
      }
    ]
  }
]

JOLT Spec Used

[
  {
    // Keeping the same three nested arrays structure,
    //  build all the output "elements" into a parallel 
    //  structure, creating a "header" object and an 
    //  array of attachment objects.
    "operation": "shift",
    "spec": {
      "*": {
        "MaterialId": "[&1].MaterialId",
        "LocationId": "[&1].LocationId",
        "OHReportingDate": "[&1].OHReportingDate",
        "TankNumber": "[&1].TankNumber",
        "stocks": {
          "*": {
            "stockStatus": {
              "OnHand": {
                "quantity": {
                  "*": {
                    "@(0,uom)": "[&7].POI",
                    "@(0,amount)": "[&7].XYZ"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]

Expected

[ {
  "MaterialId" : "na-103437",
  "LocationId" : "0TB9",
  "OHReportingDate" : "2020-08-18T20:57:16Z",
  "TankNumber" : "KTLA",
  "ReportedQtyUom" : "KG",
  "ReportedQty": "0.000"
}, {
  "MaterialId" : "na-103437",
  "LocationId" : "0TB9",
  "OHReportingDate" : "2020-08-18T20:57:16Z",
  "TankNumber" : "KTLJ",
  "ReportedQtyUom" : "KG",
  "ReportedQty" : "0.000"
}]
1
In JoltSpec insted of POI and XYZ, ReportedQtyUom and ReportedQty should be there "quantity": {"*": {"@(0,uom)": "[&7].ReportedQtyUom","@(0,amount)": "[&7].ReportedQty"}} - Giridhar Mg

1 Answers

0
votes

Your spec will check for stockStatus as onHand and tries to move one level, since OnHand is String null gets returned for the shifts written inside the quantity. Once you check for stockStatus as onHand, traverse 2 level backwards and try shifting the values.

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "MaterialId": "[&1].MaterialId",
        "LocationId": "[&1].LocationId",
        "OHReportingDate": "[&1].OHReportingDate",
        "TankNumber": "[&1].TankNumber",
        "stocks": {
          "*": {
            "stockStatus": {
              "OnHand": {
                "@(2,quantity.[0].uom)": "[&5].ReportedQtyUom",
                "@(2,quantity.[0].amount)": "[&5].ReportedQty"
              }
            }
          }
        }
      }
    }
  }
]