I’m using forms that parse JSON data returned by a snippet call. I changed the forms last week, and all of a sudden, the JSON string was disappearing from the page, even though I verified that it was indeed in the database. I just could not get the JSON string to print.
Then it occurred to me that my JSON string was formatted like this: [[],{"some":"data"},[]]
Look closer and you will notice this emulates a Snippet tag with the opening and closing brackets (which MODx promptly replaced with nothing).
In summary, you should always do a preg_replace on JSON data to place a space between any MODx conflicting opening brackets:
preg_replace(’/\[\[/’, ’[ [’, myJSON);
preg_replace(’/\{\{/’, ’{ {’, myJSON);
-
MODX Staff
- 10,725 Posts
Thanks for posting this note; it’s a great reminder that we need to add this information to the appropriate place( s ) in the documentation.