There are many situation when we send JSON formatted data in POST method to server side(PHP). But when we try to read that in the conventional way i.e. $_POST, it will show a blank array. If we analyse the content in firebug, we can see that the data is there in POST method, but in the backend it’s returning NULL.
This happens because in PHP, $_POST varriable reads in name, value pairs. PHP treats the whole JSON expression as URL name and value pairs. However, there are specific characters in JSON that have special uses when used in PHP, that’s why PHP automatically escapes the JSON expression string.
One can get the JSON data in “$HTTP_RAW_POST_DATA” variable. and then deode it to multi-dimensional array i.e. json_decode($HTTP_RAW_POST_DATA, true);
Another Way is $data = file_get_contents(“php://input”); This will also fetch the JSON encoded String.