PHP array to JSON
Convert a PHP array() or [] literal to JSON, and back again.
PHP array to JSON
Paste a PHP array written with array(...) or short [...] syntax and this tool converts it to JSON with the correct types — strings, numbers, booleans and null are all preserved rather than turned into strings. It also runs in reverse: paste JSON and generate a PHP array literal you can drop straight into your code, whether you are debugging a var_export() dump, migrating a config file, or turning an API response into a fixture for a test.
The Direction option switches between PHP → JSON and JSON → PHP, and the swap button carries the current output back into the input so you can round-trip a value and check it survives the conversion intact. When generating PHP, Use short array syntax chooses between [...] and the older array(...) form; Preserve numeric keys keeps every index explicit instead of letting a plain 0..n-1 list collapse into an implicit one; null / true / false case picks lowercase or UPPERCASE constants; and Escape apostrophes switches generated strings between single quotes (with \' escaped) and double quotes. Pretty print and Indent size control whitespace, and Sort keys orders object and associative-array keys alphabetically at every nesting level.
Parsing a PHP array understands single- and double-quoted strings with their different escaping rules, integers, floats, negative numbers, nested arrays, comments, and trailing commas. A sequential array with keys 0, 1, 2… in order becomes a JSON array; anything else — string keys, gaps, or a key that resets the counter — becomes a JSON object, as PHP's own json_encode() would treat it. Windows and Unix line endings are handled the same way, and the live tally reports the item count, line count and character count as you type.
Everything runs locally in your browser — the array you paste is never uploaded anywhere. When you're done, copy the result, download it as a .txt file, or send the output back into the input to run it through the tool again in the other direction.