json-path / JsonPath

Java JsonPath implementation
Apache License 2.0
8.94k stars 1.65k forks source link

JSON-to-JSON trasformation using JsonPath #474

Open compugeek25 opened 6 years ago

compugeek25 commented 6 years ago

Hello Team @plastic-karma @valery1707 @kysnm @trajano @johanhaleby ,

I've a requirement where, on the left I've JSON payload which is flat structure and I want to use JsonPath to construct a composite JSON structure on the right based on a model mapping specification which contains the JsonPath keys for left and right side (what on left maps to what on right).

I'm unable to construct new elements if the out put structure contains data in array. Please advise how can I be able to achieve this.?

Thanks Rajat.

Input Json:

{
        "employeeID": "999",
        "employeeName": "Rashmi",
        "addressID": "aaa"
    },
    {
        "employeeID": "999",
        "employeeName": "Rashmi",
        "addressID": "bbb"
    },
    {
        "employeeID": "999",
        "employeeName": "Rajat",
        "addressID": "ccc"
    },
    {
        "employeeID": "999",
        "employeeName": "Rajat",
        "addressID": "ddd"
    }

Output Json:

{
    "employees": [{
            "employeeID": "999",
            "employeeName": "Rashmi",
            "addresses": [{
                "addressID": "aaa"
            }]
        },
        {
            "employeeID": "999",
            "employeeName": "Rashmi",
            "addresses": [{
                "addressID": "bbb"
            }]
        },
        {
            "employeeID": "888",
            "employeeName": "Rajat",
            "addresses": [{
                "addressID": "ccc"
            }]
        },
        {
            "employeeID": "888",
            "employeeName": "Rajat",
            "addresses": [{
                "addressID": "ddd"
            }]
        }
    ]
}
valery1707 commented 6 years ago

Maybe you need use Jolt, which is designed for JSON to JSON transformation?