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

1 Answer 1

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"
                }
            }
        }
    }
}
]
Sign up to request clarification or add additional context in comments.

1 Comment

There is no such formal tutorial that I know of. But if you go through the questions and answers on Jolt issue tracker (github.com/bazaarvoice/jolt/issues), it covers various use cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.