Command Palette

Search for a command to run...

JS

JSON to PHP Array

Convert JSON into a PHP array literal. Choose short [] or array() syntax, indentation, and an optional variable assignment, then copy the result. Runs client-side.

What is a JSON to PHP Array converter?

A JSON to PHP array converter turns a JSON document into the equivalent PHP array literal you can paste straight into a script. A JSON object becomes an associative array written with the => operator, a JSON array becomes an indexed array, and the scalar types map directly: a JSON string becomes a single-quoted PHP string, true and false stay true and false, null stays null, and numbers keep their value. Instead of hand-typing brackets and arrows around a config blob or an API response, you paste the JSON and copy back ready-to-run PHP.

It exists because JSON and PHP arrays describe the same shape with different punctuation, and translating between them by hand is slow and error-prone. PHP itself reads JSON at runtime with json_decode($string, true), but that leaves the data locked inside a string and parsed on every request. Sometimes you want the array in the source: a default configuration, a lookup table, a fixture for a test, a seed for a database migration, or an example in documentation. This converter produces that literal, so the value is committed to code rather than decoded from a payload each time the script runs.

Everything happens in your browser. The JSON you paste is parsed and re-serialised in JavaScript on your own device, so nothing is uploaded, logged, or stored, and the tool keeps working with the network disconnected once the page has loaded. That matters when the JSON is a real API response, a private config, or anything with keys and values you would rather not send to a server. You can pick the modern short array syntax or the classic array() form for older codebases, set the indentation to match your style, and optionally wrap the output in a variable assignment so it drops into a file with no extra editing.

Here is a JSON object to PHP array conversion you can check. Paste {"site": "O'Reilly Books", "price": 12.50, "tags": ["php", "json"]}, type config in the $variable box and click Convert. With the default short syntax and 4-space indent, the output is $config = [ with 'site' => 'O\'Reilly Books', then 'price' => 12.5, then 'tags' => an indexed array of 'php' and 'json', closed with ];. The apostrophe is escaped with a backslash and 12.50 loses its trailing zero. For JSON to an array in PHP at runtime, json_decode($json, true) gives the same array.

How to use the JSON to PHP Array converter?

  1. Paste your JSON

    Paste a JSON object or array into the input box. Load the sample first if you want to see the shape of the output before using your own data.

  2. Choose the array syntax

    Pick short [] syntax for PHP 5.4 and later, or the classic array() form for older code. Both produce the same array; only the brackets differ.

  3. Set indentation and assignment

    Choose 2 spaces, 4 spaces, or a tab for indentation, and optionally enter a variable name to wrap the output as $name = [...]; ready to paste.

  4. Convert and copy

    Click Convert to build the PHP array, then copy it to the clipboard. Invalid JSON is reported with the exact parser message so you can fix it.

Key Features

  • Short and long array syntax

    Output modern [] literals for PHP 5.4 and later, or the classic array() form when you need to support an older runtime. Switch between them without re-pasting.

  • Associative and indexed arrays

    JSON objects become associative arrays with the => operator and JSON arrays become indexed arrays, nested to any depth exactly as the source is structured.

  • Safe single-quoted strings

    Strings are emitted single-quoted, so only a backslash and a single quote are escaped. Newlines and other characters pass through unchanged, matching PHP behaviour.

  • Optional variable assignment

    Enter a variable name to wrap the literal as $config = [...]; with a trailing semicolon, so the result drops straight into a source file with nothing left to edit.

Frequently Asked Questions

A JSON to PHP array converter transforms a JSON document into the equivalent PHP array literal. JSON objects become associative arrays with the => operator, JSON arrays become indexed arrays, and the scalar types map to their PHP counterparts so you can paste the result directly into a script.

Comments

0 comments

0/2000 characters

No comments yet. Be the first to share your thoughts!

json to php arrayjson object to php arrayjson to array in phpjson to phpconvert json to php arrayjson to php converterjson decode to arrayphp array from jsonjson to associative arrayfree json to phpno signup json to php