0

I am currently trying to get data from an webpage programmatically. I can extract a string that contains JSON from the page body but sometimes it contains double quotes which are not escaped, because the string has been rendered. Is there a possibility to use some regex to escape those double quotes? Or any other possibilites?

Example:

{
    "rows": [
        ["foobar", "here is my "double quoted" text", "2"]
    ]
}
mrvnklm
  • 1,348
  • 2
  • 10
  • 19
  • 1
    Escaping `"` as `\"` should fix the issue. Make it this `"here is my \"double quoted\" text"` – Pushpesh Kumar Rajwanshi Feb 21 '19 at 17:41
  • I think it's already answerd here: https://stackoverflow.com/questions/15637429/how-to-escape-double-quotes-in-json – Dhanapal Feb 21 '19 at 17:45
  • Possible duplicate of [How to escape double quotes in JSON](https://stackoverflow.com/questions/15637429/how-to-escape-double-quotes-in-json) – blhsing Feb 21 '19 at 17:47
  • Not really, due to the fact, that I am pulling the data off a website, adding backslashes is by hand is not an option. I searched for an answer for about half an hour, found nothing. To be more precise I am going to update the question. – mrvnklm Feb 21 '19 at 19:06
  • May be helpful if you post the minimal code that you are using to retrieve the data in the first place. – benvc Feb 21 '19 at 19:28
  • 1
    @benvc I don't think so, it is just `document.getElementById('id').innerText` – mrvnklm Feb 21 '19 at 20:41
  • So the element you are getting `innerText` from contains a string representation of the invalid JSON in your example? – benvc Feb 21 '19 at 21:27
  • 1
    @benvc yes, the request url renders html. It only returns raw data to xhr request, which I can't send or intercept – mrvnklm Feb 22 '19 at 09:23

0 Answers0