0

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:

  1. Tokenize the jsonpath query
  2. For the tokens, build intricate structure using Map
  3. Convert the Map to JSON object/string
2
  • 1
    "I have not tried in Node.js or TypeScript, but have tried in Java." Do you know how to program in JavaScript or TypeScript? Or just Java? Commented Oct 30, 2023 at 13:25
  • I have written a custom solution in java, by tokenising the jsonpath and evaluating it to get the resultant json object. But as seen here stackoverflow.com/questions/66560805/… there is a readymade library that does it, so was wondering is there any such solution available in node or typescript or will I have to replicate my earlier implementation here in node as well and also looking for some recommendations to implement it. I am new to JS/ Node/ TS and learning it, given a logic I can implement in these languages as well Commented Oct 31, 2023 at 9:54

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.