Overview
Convert JSON into PHP array literal syntax, or a PHP array literal back into JSON, using a small purpose-built tokenizer and parser rather than a regex substitution - regex can’t reliably handle nested arrays, quoted strings containing commas or brackets, or PHP’s "=>" key syntax, so this walks the actual token structure instead. PHP output uses modern short array syntax ([...]) with single-quoted string keys; a PHP array with sequential integer keys starting at 0 converts to a JSON array, while string keys or out-of-order integer keys convert to a JSON object, matching how PHP’s own json_encode() treats arrays. Useful for moving config or fixture data between a JS/JSON codebase and a PHP one, or reading a PHP array literal from a legacy config file as JSON. Runs entirely client-side.
Best for: Moving fixture or config data between a JS/JSON codebase and a PHP one
How to use this tool
- Pick a direction. Switch between JSON → PHP and PHP → JSON with one click.
- Paste your input. Drop in a JSON object/array or a PHP array literal.
- Read the converted output. Sequential arrays and associative arrays are distinguished automatically, matching PHP’s own conventions.
- Swap and repeat. Use the swap button to feed the output straight back in as new input.
Why use this tool
Real parsing, not regex
A small tokenizer and parser handle nested arrays and quoted strings correctly, which a regex-based approach can’t do reliably.
Matches PHP’s array/object convention
Sequential integer-keyed arrays become JSON arrays; everything else becomes a JSON object, the same rule PHP’s json_encode() uses.
Modern short array syntax
JSON → PHP output uses [...] rather than the older array(...) form, matching current PHP style.
Nothing leaves your browser
Conversion happens entirely client-side - useful when the data includes real config values or fixture data.
Frequently asked questions
Yes for parsing PHP → JSON - both array(...) and [...] are accepted as input. JSON → PHP output always uses the modern short [...] syntax, since that’s the current PHP style recommendation.
A PHP array with sequential integer keys starting at 0 (whether those keys are explicit or just implied by position) converts to a JSON array. Any array with string keys, or with integer keys that skip a number or start somewhere other than 0, converts to a JSON object instead - the same rule PHP’s built-in json_encode() function uses.
No - this only handles plain array literals: strings, numbers, true/false/null, and nested arrays. PHP objects, closures, constants, and variables aren’t valid inside a plain array literal in the way this parser expects, and won’t convert.