I am using WinDEV Mobile to dynamically build Javascript controls. I have a problem when new lines or * is used within the JSON. When I remove them, the following code works:
const json = `[{"id":1,"data":{"visible":true,"visibleFunction":"","repeatCount":1,"required":"false","readOnly":false},"text":"Some RandomnnWords With a \nnAnd new lines","type":"textbox"}]`;
console.log(JSON.parse(json));
However, when they’re left in there, the error I receieve is the following due to the escaped * characters:
SyntaxError: JSON.parse: bad control character in string literal
I have no control on WinDEV Mobile to alter how this is passed in as it doesn’t support many JSON functions to change this and I need to support the new lines.
I originally tried to do a .replace()
to convert any to
\
but the issue is, this JSON definition can have Base64 images inside of it which then fails to parse.
Is there anything I can do in Javascript to prevent the unescaping of the n
and \
?