PHP Array to JSON
Paste a PHP array literal, a var_export dump or a config file return statement and get valid JSON back. Understands both array() and short syntax, nested arrays, constants and trailing commas.
Last reviewed by the Radiatus Cloud team
Need this built for your product?
We design, build & host secure software & APIs.
The daily copy and paste problem
PHP config files, Laravel service configs, WordPress option dumps and var_export debugging output are all PHP array literals. Getting one of them into a JavaScript console, a JSON body, a documentation example or a test fixture means converting the syntax by hand: replacing fat arrows with colons, converting single quotes, removing trailing commas and quoting bare keys. It takes a few minutes each time and produces a typo every third attempt.
Two syntaxes and several quirks
PHP arrays come in the old array() form and the short bracket form, often mixed within one file. Keys can be quoted strings, integers, or unquoted constants. Values can be nested arrays, null, true and false in any case, integers with underscores as separators, floats, hexadecimal and octal literals, and single or double quoted strings with different escaping rules. Trailing commas are legal everywhere. A converter that handles only the common case fails on the file you actually have.
Lists versus maps
The other real difference is structural. A PHP array with sequential integer keys starting at zero is a JSON array; anything else is a JSON object. That is exactly the rule json_encode applies, and it is why a list with one element removed suddenly serialises as an object in production. This converter applies the same rule and tells you when an array was treated as a map because its keys were not a clean sequence, which is usually the bug you were looking for.
Related tools
- JSON Formatter — Format and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
- JSON Validator — Validate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
- Regex Tester — Test regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.
- HTML Minifier — Minify HTML by removing comments and redundant whitespace, without breaking inline elements or pre blocks. Runs entirely in your browser.
Frequently Asked Questions
Does it run any PHP?
No. The input is parsed as text by a small recursive descent parser in your browser. Nothing is executed and nothing is uploaded, which is the point: pasting a config file into a remote evaluator is not something to do casually.
Why did my list become a JSON object?
Because the keys were not sequential integers starting at zero. json_encode behaves identically, so this is showing you real PHP behaviour rather than a conversion quirk. Reindex with array_values to get an array.
Are constants and expressions supported?
Bare identifiers such as PHP_INT_MAX or a class constant cannot be resolved without running PHP, so they are emitted as strings and flagged. Concatenation and function calls are reported as errors rather than guessed at.
Does it handle var_export output?
Yes, including the leading array ( and the \ prefixed class names that var_export emits for objects. Object dumps are converted to plain JSON objects since JSON has no class notion.
What about very large arrays?
Parsing is linear and runs comfortably on files of a few megabytes. Extremely large dumps are better handled with a short PHP script calling json_encode directly.
Privacy & Security
Everything runs in your browser; nothing is uploaded.
How to Use
Paste a PHP array or var_export output and press Convert to get JSON.
Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.
Related Tools
JSON Formatter
DeveloperFormat and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
JSON Validator
DeveloperValidate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
Regex Tester
DeveloperTest regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.