0

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.

3
  • I think this is what are you looking for: stackoverflow.com/a/53529755/8291949 Commented Dec 17, 2020 at 23:20
  • In the above example JSON pointer works with array indexes, in the above case i am trying to find object from arrays based based on a field value. Commented Dec 17, 2020 at 23:35
  • It's not a direct answer to your effort. For me, the main takeaway of the linked answer was: There is no such feature, and you may have to build your own facility to make it happen. Commented Dec 18, 2020 at 0:52

0

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.