0

I have an array of JSON objects but its structure is unknown.i have struck with how to get the value and based on value i need to generate code

    "memberjson": [{
        "company": {
            "employee": {
                "software": {
                    "employeetype": "permanent"
                },
                "type1": "401",
                "type2": "541"
            }
        }
    }, {
        "trust": {
            "people": {
                "contract": {
                    "type": "available"
                },
                "type4": "4541",
                "type5": "58771"
            }
        }
    }]

}

How to get the value however I can request to give the path Example

JSON path 1: company.employee.software.employeetype

JSON path 2: trust.people.contract.type^trust.people.type4^trust.people.contract.type4

Based on the path I need to get the value.

in which format I need to store path so that I can get the value easily or please suggest me is there any other way to get the value for the unknown structure

Also, I need to generate code from above JSON:

Ex: For JSON path 1: company.employee.software.employeetype^employee.company.type1^ ^employee.company.type2 "generatedkey"=company.employee.software.employeetype+employee.company.type1+employee.company.type2

Final Ans: "generatedkey":"permanent401541"

JSON path 2: trust.people.contract.type^trust.people.type4^trust.people.contract.type4 "generatedkey"=trust.people.contract.type+trust.people.type4+trust.people.contract.type4

Final Ans: "generatedkey":"available454158771"

I tried to iterate based on a path

1 Answers1

2

There is a library called JSON Path https://www.npmjs.com/package/jsonpath, here you write regular expression for the path to get the value

To test use this online tool called json path evaluator https://jsonpath.com/ to verify your path

Pranoy Sarkar
  • 1,965
  • 14
  • 31