Create JSON from path using java

848 Views Asked by At

I need to create a JSON from path. for e.g my paths and its values looks like below

root/departments[name=dept1]/employees[id=emp1]/firstName = firstName
root/departments[name=dept1]/employees[id=emp1]/lastName = lastName
root/departments[name=dept1]/employees[id=emp2]/firstName = firstName
root/departments[name=dept2]/employees[id=emp1]/firstName = firstName

from this i need to generate json which looks like this.

{
"root": {
    "departments": [
        {
            "name": "dept1",
            "employees": [
                {
                    "id": "emp1",
                    "firstName": "firstName",
                    "lastName": "lastName"
                },
                {
                    "id": "emp2",
                    "firstName": "firstName"
                }
            ]
        },
        {
            "name": "dept2",
            "employees": [
                {
                    "id": "emp1",
                    "firstName": "firstName"
                }
            ]
        }
    ]
}

}

When i checked into JsonPath and JsonPointers this kind of structure is not supported.

0

There are 0 best solutions below