Search code examples
javascriptjsonparsingbracketssquare

JSON Parse with square brackets inside data


I am trying to parse a JSON string which contains square brackets inside the string.

For example

"[[\"hello\", \"i\", \"like [cows]\"], [\"what\", \"about [you]?\"]]"

It shows an error while parsing:

Uncaught SyntaxError: Unexpected token [

How can I parse the string anyway while leaving the brackets as they are?


Solution

  • I found the problem. I needed to use addslashes() around the strings in the PHP code which serves the code. There was a part of a string containing [C:\].