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?
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.
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.
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.
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
Related Tools
CSV Viewer
Open, search, and sort CSV files as a clean table in your browser. Auto-detects delimiters, handles quoted fields, and exports to CSV or JSON.
JSON to Go Struct
Convert JSON into Go struct definitions with json tags. Nested objects become inline structs, arrays of objects are merged, and field names follow Go conventions. Runs client-side.
Ask Questions
Find the questions people are actually asking about a topic on Reddit in the last two months, cleaned into headings you can build an article around.
Chmod Calculator
Convert Unix file permissions between octal, symbolic and rwx checkboxes. Toggle read, write and execute for owner, group and others, plus setuid, setgid and sticky, and copy the chmod command - all in your browser.
Comments
0 comments
No comments yet. Be the first to share your thoughts!