Supposed I have a string that contains JSON:
{"foo":"bar"}
Then I can easily parse this using the JSON.parse function.
Now supposed the string has some additional prefix, such as:
blah: {"foo":"bar"}
Then simply using JSON.parse does not work, of course. What I'd need to do is to extract a substring and then run the function. Now supposed I do not know the content or the length of the prefix (i.e., I don't know whether it finishes with a colon and a space, or whether it is always six characters long, or …): What is the best way to parse the contained JSON?
The most obvious way would probably be to just find the index of the first {, but this won't work if the string itself contains a {.
Is there a better, i.e. more reliable, way to do this?