- Mark as New
- Follow
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Hi Milan,
Unfortunately, trying to correct the JSON string before parsing is going to be incredibly complicated. I'm saying this because the field in question (street) seems to be free-text, so it will be basically impossible to identify what is JSON syntax and what is field content.
Imagine I entered the following value for the street field:
Fake Street", "fakeProperty": "fake
This would result in the following JSON (expected JSON syntax in blue, value in underlined red)
"street: "Fake Street", "fakeProperty": "fake"
As you can see, this is actually valid JSON! I don't know where your data comes from, but if it comes from an input form for example, then anybody could manipulate your JSON (and resulting JS objects) by entering such values in the input form fields, and you would never be able to detect it as "invalid" (at least not in a generic way).
For that reason I don't think that finding a JS hack to solve to fix the JSON string is the right way to solve the issue. Instead, i think you should attempt to fix the method of fetching the JSON so that it maintains its correctly escaped format. Could you tell us how you're doing that?
If that is not possible for whatever reason, then try to avoid double-quotes in the data by adding stricter validation on input and doing a one-shot fix for all existing data.