[PHP] How to receive JSON data sent by POST

I created an API on the PHP side, and when I try to get the JSON data sent by POST, I couldn’t receive the POST data with $ _POST, so make a note.

According to the official, $ _POST can be received when the “HTTP Content-Type” is as follows.


So application/json couldn’t be received in $ _POST.

How to use JSON sent by POST to PHP as data

This is how to retrieve the actually POSTed data.

//  get raw data from the request 
$json = file_get_contents('php://input');
// Converts json data into a PHP object 
$data = json_decode($json, true);

Reference Receive JSON POST with PHP