JSON to PHP Array Converter
Paste JSON and get a ready-to-paste PHP array literal — pick short or long syntax, optionally wrap it in a `$variable = ...;` assignment.
Last updated: May 27, 2026
Find this tool useful? Support the project to keep it free!
Buy me a coffeeWhat is JSON to PHP Array Converter?
PHP has its own array literal syntax. Modern PHP (5.4+) uses square brackets — `['key' => 'value']` — and older code uses the `array(...)` function form. JSON is structurally similar to PHP associative arrays, so converting is mechanical: object keys become string keys, arrays stay arrays, and primitives map onto PHP's scalars.
The tricky parts are string escaping and the choice of literal form. This tool emits single-quoted PHP strings (which don't interpolate variables and only require escaping `\` and `'`) and lets you pick between short and long syntax. You can optionally wrap the result in a variable assignment so it's a complete statement ready to drop into a script.
How to Use JSON to PHP Array Converter
Paste JSON into the input panel.
Pick short [ ] or long array( ) syntax.
Optionally enter a variable name to produce `$name = ...;` output.
Adjust indent and semicolon options.
Copy the PHP array literal.
Common Use Cases
- Importing a JSON fixture into a PHP test or seed file.
- Embedding configuration values from a JSON file into PHP source code.
- Producing a PHP array literal for a translation table or a lookup map.
- Migrating between a JSON-based and PHP-array-based configuration format.
Example Input and Output
A flat JSON object becomes a short-syntax PHP array with a variable assignment.
{ "name": "Alice", "age": 30, "active": true }$user = [
'name' => 'Alice',
'age' => 30,
'active' => true,
];Privacy
All conversion happens in your browser. No JSON is sent to a server.
Compatibility
Short array syntax requires PHP 5.4 or later. For legacy PHP environments, switch to long array( ) syntax.

