1

I have Json data as follows:

{
   "template" : [
      "{
         "Id": "abc"
      }"
   ]
}

I am using JSONPath to extract data from the Json above. I would like to extract the "Id" data from the Json using JsonPath.

The problem I see is, the data is being treated as a string and not as a Json as shown below.

"{
   "Id": "abc"
}"

If there were no double-quotes I could have used JsonPath as follows:

$.template[0].Id

But due to the double-quotes, I am unable to access the "Id" data. I suspect there is a way to access this data using JsonPath-Expression but I am pretty much a novice here and no amount of research helped me out with a resolution.

How do I treat it as a Json and not as a string using JsonPath? Kindly help me out here.

mang4521
  • 742
  • 6
  • 22
  • Your JSON is invalid. The interior quotes (i.e. around `Id` and `abc`) should be escaped. – gregsdennis Jun 05 '22 at 09:05
  • Yes I am aware of this and that is precisely the issue here. I got to deal with those quotes and preferably using JsonPath. – mang4521 Jun 05 '22 at 11:33
  • 1
    Can you edit your question to better explain what you're trying to do? JSON Path is only going to work on valid JSON. – gregsdennis Jun 05 '22 at 19:45

1 Answers1

1

JSON Path isn't going to be able to parse JSON that's encoded within a string. You need to perform three operations:

  1. Get the string (use JSON Path or something else)
  2. Parse the string as JSON.
  3. Get the data you're looking for on that (JSON Path or something else)
gregsdennis
  • 7,218
  • 3
  • 38
  • 71