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.
Frequently Asked Questions
Why single-quoted strings?
Single-quoted PHP strings do not interpolate variables or process most escapes — they are the safe default for literal data. You only need to escape \\ and ' in the contents.
What about nested objects and arrays?
Both are handled recursively. JSON objects become PHP associative arrays with string keys; JSON arrays become PHP indexed arrays.
Why does the output have a trailing comma?
PHP allows trailing commas in array literals, and they keep diffs clean when you add or remove items. Disable the trailing semicolon checkbox only — there is no toggle for the comma since it harms nothing.
Does this send my JSON anywhere?
No. All conversion happens locally in your browser.
Related Tools
JSON Formatter
Format, validate, and beautify JSON instantly — with clear error messages, Tree View, Diff mode, and Schema validation.
JSON to XML Converter
Convert JSON to XML online. Nested objects and arrays are mapped to XML elements with configurable root element name and optional XML declaration.
JSON to TypeScript Interface
Convert any JSON object into TypeScript interfaces instantly — handles nested objects, arrays, union types, optional fields, and generics.
HTML to PHP Converter
Wrap HTML markup in PHP echo, heredoc, nowdoc, or printf statements. Six output styles including per-line echo and properly escaped strings. Copy or download as .php.
JSON Validator
Validate JSON syntax online. Shows valid/invalid status, error location (line and column), and structure stats including type, key count, and depth.
JSON Fixer
Fix broken or invalid JSON automatically. Repairs trailing commas, single quotes, bare keys, Python literals, and JavaScript comments.

