Send POST data via raw JSON with Postman

Send POST data via raw JSON with Postman

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Why Postman Raw JSON Doesn't Populate $_POST in PHP

If you are sending a POST request via Postman with raw JSON, setting the body to { "foo": "bar" }, and configuring the header as Content-Type: application/json, but then printing an empty array from print_r($_POST) on the PHP side, there is a fundamental mismatch in how the data is being transmitted versus how PHP expects to receive it.

The core issue lies in the distinction between form-encoded data and raw JSON payloads. When you use jQuery's $.ajax method with the data property set to an object like { "foo": "bar" }, the library automatically serializes that object into a URL-encoded string (e.g., foo=bar) and sets the appropriate headers. This format aligns perfectly with how PHP populates the superglobal $_POST.

In contrast, when you manually select "raw" in Postman and paste JSON directly into the body field, you are bypassing that automatic serialization. You are sending a literal string containing valid JSON syntax. To make this work correctly, PHP does not look at the Content-Type header to decide how to parse the body; instead, it relies on the presence of specific magic bytes or headers to switch parsing modes.

To fix this immediately, you must enable PHP Input Validation in your application settings. Without this setting enabled, PHP assumes that any request with a Content-Type of application/json should be parsed into the $_POST superglobal, but it actually expects the body to be URL-encoded. If your server configuration does not have input validation strictly enforcing the content type match, PHP might ignore the JSON header and treat the raw string as empty or malformed text, resulting in an empty array.

The correct approach involves switching from $_POST to $_RAW_POST_DATA. When you send raw JSON, the data arrives in the request body as a string. By default, PHP does not automatically decode this string into an associative array unless specific conditions are met. Accessing $_POST on a raw JSON payload often returns an empty array because PHP is waiting for form-encoded data (like foo=bar) even though the header claims it is JSON.

To access your data correctly, you should read the raw input stream or use the input_json filter if available in your version of PHP. However, the most robust and common pattern for handling APIs is to switch to using php://input. This allows you to read the raw request body as a string:

$json = file_get_contents('php://input');
$data = json_decode($json, true);
print_r($data);

This will output your array correctly:

Array
(
    [foo] => bar
)

There is no issue with Postman itself; the tool is functioning exactly as designed by sending a raw JSON payload. The discrepancy arises from the backend expecting a different format than what was sent. If you are using Laravel, the framework handles this gracefully by default in most versions, automatically mapping JSON payloads to the request()->input() method and populating the request object, rather than relying on $_POST.

If you must stick with $_POST for legacy reasons or specific logic requirements, ensure that your server is configured to validate input strictly. In some environments, enabling input validation forces PHP to decode JSON bodies into $_POST automatically if the Content-Type header matches, but this behavior can vary based on the PHP version and specific server configuration.

Understanding these distinctions prevents confusion when debugging API integrations. Always verify whether your backend is expecting URL-encoded data or raw JSON. If you are building APIs for Laravel projects, leveraging the built-in request handling ensures that you don't have to manually parse php://input every time, though understanding the underlying mechanism remains crucial for troubleshooting edge cases.

Our network