简体   繁体   中英

JSON to JSON using JOLT Transformation

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

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"
                }
            }
        }
    }
}
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM