JSON Formatter for PHP Developers – Debug json_encode Output

PHP's `json_encode()` is deceptively simple to call and surprisingly easy to get wrong — from UTF-8 encoding issues that silently return `false` to floating-point precision problems that corrupt numeric values. When your Laravel API returns a garbled JSON response or your Symfony serializer produces unexpected output, the fastest path to a fix is reading the raw JSON clearly. This tool is the PHP developer's quick-debug companion: paste the output of `json_encode()`, a Laravel JSON response body, or a JSON string from a PHP config file, and get an immediately readable, color-coded view. It's particularly useful when debugging `JSON_THROW_ON_ERROR` issues in PHP 7.3+, verifying that `json_encode($data, JSON_PRETTY_PRINT)` is producing the structure you expect, or checking that your PHP array correctly mapped to a JSON object (with string keys) rather than a JSON array.

Open JSON Formatter →

What Is JSON Formatter for PHP Developers – Debug json_encode Output?

PHP JSON formatting takes the output of PHP's `json_encode()` function — typically a compact string — and expands it into an indented, human-readable structure. PHP developers use JSON formatting to verify serialization output, debug encoding errors, and confirm that PHP arrays and objects map to the expected JSON structure.

How to Use the JSON Formatter

  1. Step 1: Capture the JSON output from your PHP application — log it with `error_log(json_encode($data))` or output it in a test response.
  2. Step 2: Copy the raw JSON string from your log, browser, or test output.
  3. Step 3: Paste it into the input area above.
  4. Step 4: Click 'Format' to expand the JSON and reveal its structure.
  5. Step 5: Check for unexpected null values that might indicate a `json_encode()` failure (returns false or null on error).
  6. Step 6: Verify that PHP associative arrays (string-keyed) appear as JSON objects `{}` and indexed arrays appear as JSON arrays `[]`.

Example

{
  "status": "success",
  "data": {
    "user_id": 3390,
    "username": "php_dev",
    "permissions": ["read", "write", "admin"],
    "meta": {
      "last_login": "2026-05-04T18:30:00+00:00",
      "session_count": 142
    }
  },
  "errors": null
}

Pro Tips

Ready to Try It?

Free, browser-based, no signup required.

Launch JSON Formatter Free →

FAQ's

Common causes: non-UTF-8 encoded strings in your data (use `mb_convert_encoding()` first), NaN or INF float values, resources that can't be serialized, or recursive array references. Call `json_last_error_msg()` immediately after the failed call to get the specific error message.

Use `json_encode($data, JSON_PRETTY_PRINT)` to produce formatted JSON in PHP. This produces the same indented output as this formatter. Use this tool when you need to inspect JSON outside your PHP environment or share it with someone without a PHP runtime.

PHP encodes as a JSON array only when keys are consecutive integers starting at 0. If your array has string keys, gaps in integer keys, or you added elements with string keys, `json_encode()` produces a JSON object `{}` instead of an array `[]`. Format the output to confirm which you're getting.

Yes. Laravel's API resources and JSON responses produce standard JSON. Copy the response body from your browser's Network tab or from a PHPUnit test response assertion, paste it here, and format it for inspection.

PHP `DateTime` objects are not natively JSON-serializable — `json_encode()` produces an object with internal properties that's rarely what you want. Use `$date->format(DateTime::ISO8601)` to convert to a string first, or implement `JsonSerializable` on your model class.

`json_encode()` produces standard JSON readable by any language. `serialize()` produces a PHP-specific binary format only readable by PHP's `unserialize()`. Always use `json_encode()` for data exchanged with other systems; reserve `serialize()` for PHP-internal caching.

Yes — if you store configuration as JSON files (common in Composer-based projects or custom config systems), paste the file contents here to validate syntax before deploying. A JSON syntax error in a config file typically causes a fatal application error at runtime.