JSON to PHP Array

Convert JSON to PHP arrays with json_decode and json_encode examples.

{{ jsonToPhpArray.message }}

Overview

PHP was created by Rasmus Lerdorf in 1994 and over three decades became the most widely used server-side language on the web, especially through platforms like WordPress (which powers roughly 40% of all websites), Drupal, Magento, Laravel, and Symfony. Despite persistent comments and posts scattered across the internet saying that 'PHP is going to die, switch to X language', it remains popular, widely used, and constantly updated (I personally love my PHP). In all these environments, consuming REST APIs that return JSON is an everyday operation: receiving data from external services, reading webhooks, or building integration pipelines.

PHP handles JSON with two native functions: `json_decode()` and `json_encode()`. The most important point is the second argument of `json_decode()`: when `true`, the function returns associative arrays accessed with square brackets; when `false` (default) or omitted, it returns `stdClass` objects accessed with the arrow operator. For modern PHP 8 code with type declarations, associative arrays are generally preferable as they behave more predictably in static analysis.

Some useful flag combinations for `json_encode()`: `JSON_PRETTY_PRINT` formats with indentation for debugging and readable file generation; `JSON_UNESCAPED_UNICODE` preserves accented and special characters without converting them to `\uXXXX` escapes, essential for working with Portuguese, Spanish, and other languages; `JSON_UNESCAPED_SLASHES` avoids unnecessary slash escaping; `JSON_THROW_ON_ERROR` (since PHP 7.3) makes the function throw a `JsonException` instead of silently returning `false`, which is critical in production code where silent failures lead to hard-to-trace bugs.

This tool takes the JSON you paste and generates the equivalent PHP snippets for decode and encode, with the most useful flags pre-configured. Useful to get started quickly without having to memorize parameter order or look up documentation. Always validate the result when the JSON comes from an external source such as an API response or file upload.

Technical deep dive

Common questions summarized

  • What is this tool for?: It runs fully in your browser: useful to validate, format, or convert data in everyday development.
  • Are my inputs sent to a server?: Processing happens locally with JavaScript. We do not store what you paste into the text areas.
  • Can I use this for real production data?: Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.

Sample payload to try

  • See also the larger "Code Snippets" sample; paste this excerpt to try locally: Example — $arr = json_decode($json, true); $json = json_encode($arr, JSON_PRETTY_PRINT);

Tool guide

  • What JSON is A text format for exchanging data in APIs, webhooks, queues, and config files.

  • What PHP is and where it is used PHP is a backend language widely used in dynamic websites, CMS platforms, and server-side APIs.

  • What object the tool manipulates Input JSON (object, array, primitives) and output in PHP array syntax.

  • What the tool does Converts JSON into PHP array structure and includes practical json_decode and json_encode examples.

  • Parse/generate examples in PHP json_decode($json, true) to parse; json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) to generate JSON.

Code Snippets

Code example
$arr = json_decode($json, true);
$json = json_encode($arr, JSON_PRETTY_PRINT);

Example

$arr = json_decode($json, true);
$json = json_encode($arr, JSON_PRETTY_PRINT);

FAQ

What is this tool for?

It runs fully in your browser: useful to validate, format, or convert data in everyday development.

Are my inputs sent to a server?

Processing happens locally with JavaScript. We do not store what you paste into the text areas.

Can I use this for real production data?

Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.