PHP read POST json data

Imagine you have a webhook on your server and someone sends a JSON body POST to it.

The data is not available in the global $_REQUEST or $_POST variables as you’d expect.

To access the JSON data you’ll need to get the POST’s RAW DATA:

$postData = file_get_contents("php://input"); // <-- eg: {"key":1, "key2":2}
$arr_data = json_decode($postData, true); // <-- array('key1' => 1, 'key2' => 2)

More on this:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>