1
votes

I need to get below Expected json response after jolt transformation but am getting array for the fields orderId, subId which i want to have as part of separate object for orderItemId. Could you please help me if there is any issue with the below spec. I tried best to find a solution but could not able to. Please help.

JsonInput:

{
  "Employees": {
    "employees": [
      {
        "employeeDetails": [
          {
            "productName": "Iphone 7 Plus",
            "actionType": "ADD_PHONE",
            "status": "DELIVERY",
            "subId": "sub1",
            "id": "920040222"
          }
        ],
        "status": "SUBMITTED",
        "id": "920040221",
        "currency": "USD"
      },
      {
        "employeeDetails": [
          {
            "productName": "Iphone 7 Plus",
            "actionType": "ADD_PHONE",
            "status": "DELIVERY",
            "subId": "sub2",
            "id": "920040224"
          },
          {
            "productName": "Iphone 8 Plus",
            "actionType": "ADD_PHONE",
            "status": "DELIVERY",
            "subId": "sub3",
            "id": "920040225"
          }
        ],
        "status": "SUBMITTED",
        "id": "920040223",
        "currency": "USD"
      }
    ]
  }
}

Jolt Spec:

[
  {
    "operation": "shift",
    "spec": {
      "Employees": {
        "employees": {
          "*": {
            "employeeDetails": {
              "*": {
                "actionType": {
                  "ADD_PHONE": {
                    "@(2,productName)": {
                      "Iphone 7 Plus|Iphone 8 Plus": {
                        "@(4,status)": {
                          "*": {
                            "@(6,id)": "ids[].itemId",
                            "@(8,id)": "ids[&9].orderId",
                            "@(6,subId)": "ids[&9].subId"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]

Actual Output:

{
  "ids" : [ {
    "itemId" : "920040222",
    "orderId" : "920040221",
    "subId" : "sub1"
  }, {
    "itemId" : "920040224",
    "orderId" : [ "920040223", "920040223" ],
    "subId" : [ "sub2", "sub3" ]
  }, {
    "itemId" : "920040225"
  } ]
}

Expected Output:

{
  "ids" : [ {
    "itemId" : "920040222",
    "orderId" : "920040221",
    "subId" : "sub1"
  }, {
    "itemId" : "920040224",
    "orderId" : "920040223",
    "subId" : "sub2"
  }, {
    "itemId" : "920040225",
    "orderId" : "920040223",
    "subId" : "sub3"
  }]
}
1

1 Answers

0
votes

You have to preserve the array within an the array and then transform it to the desired output:

[
  {
    "operation": "shift",
    "spec": {
      "Employees": {
        "employees": {
          "*": {
            "employeeDetails": {
              "*": {
                "actionType": {
                  "ADD_PHONE": {
                    "@(2,productName)": {
                      "Iphone 7 Plus|Iphone 8 Plus": {
                        "@(4,status)": {
                          "*": {
                            "@(6,id)": "[&9].[&7].itemId",
                            "@(8,id)": "[&9].[&7].orderId",
                            "@(6,subId)": "[&9].[&7].subId"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "ids.[]"
      }
    }
  }
]