0

I am new to JOLT and got stuck up this requirement, i saw some examples online but in my requirement i needed to add element in a new structure. I hope anyone will be able to understand what i am trying to say

Input JSON

[
    {
        "ROWSET": {
            "ROW": {
                "CLTCORP": "1000",          //This is CorpId
                "CTLITEM": "5000",          //This is CorpItemCd
                "WHID":  "17",              //This is WarehouseId
                "CTLFAC":  "AAHC",          //This is FacilityName
                "CORP":    "001"            //This is CorpItem
            }
        }
    }
]

This is expected JSON

{
    "SupplyItemData": {
                        "CorpId": 1000,
                        "CorpItemCd": 5000
                            "Warehouse": [{
                                    "WarehouseId": 17,
                                    "FacilityName": "AAHC"
                                        }]
                            "CorpItem": 001
                        }
}

Any help or suggestion is appreciated.

I followed few links Transform JSON-JSON JOLT but could not relate exaclty to my use case

Touseef Zaki
  • 59
  • 2
  • 10

1 Answers1

2

You can use the shift operator to do this. First use the * operator to interate through the root level array. Then inside that, simply map the fields to new field names as follows.

[
{
    "operation": "shift",
    "spec": {
        "*": {
            "ROWSET": {
                "ROW": {
                    "CLTCORP": "SupplyItemData.CorpId",
                    "CTLITEM": "SupplyItemData.CorpItemCd",
                    "WHID": "SupplyItemData.Warehouse.[0].WarehouseId",
                    "CTLFAC": "SupplyItemData.Warehouse.[0].FacilityName",
                    "CORP": "SupplyItemData.CorpItem"
                }
            }
        }
    }
}
]
Udith Gunaratna
  • 2,091
  • 1
  • 13
  • 17
  • There is no such formal tutorial that I know of. But if you go through the questions and answers on Jolt issue tracker (https://github.com/bazaarvoice/jolt/issues), it covers various use cases. – Udith Gunaratna Sep 17 '19 at 02:22