I am currently facing an issue with a JSON string that I am trying to parse using the JSON.parse method. The problem seems to be related to the presence of backslashes and parentheses in the string, which results in an 'invalid character' error.
While online parsers handle the string correctly, my JavaScript code fails to parse it. I have attempted to clean the string in various ways, such as replacing backslashes, but have been unsuccessful in getting it to parse.
var cleanData = data.replace(/\\"/, /\\\\/);
Below is a snippet of the JSON file that is causing the parsing issue. Removing this portion allows the JSON.parse method to work, leading me to believe the problem is isolated to this specific part. Can anyone suggest a general clean method that could help me parse this successfully?
'{"Properties" : {
"GenerationId" : 9223372036854776000,
"indexSystem" : "",
"ExecutionTimeMs" : 109,
"QueryModification" : "path:\"https://mysite.sharepoint.com/sites/Test\" (IsDocument:\"True\" OR contentclass:\"STS_ListItem\") ContentTypeId:0x0120D5200098CBB075E51C8C4398ECCB4B4928912D*",
"RenderTemplateId" : "~sitecollection/_catalogs/masterpage/Display Templates/Search/Group_Default.js",
"StartRecord" : 0,
"piPageImpressionBlockType" : 2
}}
Any suggestions on how to tackle this issue would be greatly appreciated. Thank you.