When I put this into a json checker, it’s a valid json, but the json_decode in php gives a decode error. json partial:
"regex":{
"validator":"Regex",
"options":{
"pattern":"\/^[a-zA-Z\\.\\- ]+$\/",
"messages":"Please use letters, spaces, period and dashes only"
}
}
I looked at Regular expression messing up json_decode(); but that didn’t help me.
Thanks!
Here is the entire json:
This works.
Notice the entire JSON string was encapsulated with
{}and also notice all backslashes were escaped with another backslash (so where regex wants \ we have \\). This works perfect.NOTE UPDATE:
Just
str_replace("\\", "\\\\", $json);and you will be fine. Also, if this is submitted in a form it SHOULD be fine. I just submitted your entire JSON string through an HTML form and sent it directly tojson_decode(without escaping) and it worked. This is because the browser escapes backslashes already. So long we are not defining the string within PHP it will be escaped (atleast backslashes)