How can I convert a given jsonpath string and values to a JSON object in Node.js or TypeScript?
For reference, the problem is elaborately defined here: Create JSON Object from various JSON Path
Given:
$.student.firstName = "Abc"
$.student.subject['physics'].mark=100
I want to build:
{
"student":{
"firstName": "Abc",
"physics":{
"mark":100
}
}
}
I have not tried in Node.js or TypeScript, but have tried in Java. What I can do is:
- Tokenize the jsonpath query
- For the tokens, build intricate structure using Map
- Convert the Map to JSON object/string