Paste JSON and get clean PHP array code with short [ ] or classic array( ) syntax, aligned => arrows, or exact var_export() output, ready for config files, seeders and tests. Switch direction to turn a PHP array literal back into JSON. Everything runs in your browser.
Last updated:
Everything is converted locally in this tab; nothing is uploaded or executed. Tip: Ctrl + Enter converts.
Advertisement
Advertisement
How to use the JSON to PHP Array
Choose the direction: JSON → PHP array, or PHP array → JSON.
Paste your input or open a .json or .php file. A sample is loaded so you can see the result right away.
Pick the output style: short or long array syntax or var_export(), a variable or return statement, indent and alignment (or the JSON flags in reverse mode).
Press Convert. With Live update on, the output refreshes as you type.
Copy or download the .php or .json file, or press Swap direction to round-trip the result.
In PHP you would get the same array from json_decode($json, true), and json_encode($data) turns it back into the original JSON.
JSON and PHP types side by side
JSON
PHP (short syntax)
var_export()
"text"
'text'
'text'
"line\nbreak"
"line\nbreak"
quoted with a real line break
42 / 4.5
42 / 4.5
42 / 4.5
true / false
true / false
true / false
null
null
NULL
[1, 2]
[1, 2]
array ( 0 => 1, 1 => 2, )
{"a": 1}
['a' => 1] or (object) ['a' => 1]
array ( 'a' => 1, )
{} / []
[]
array ( )
Round-trip gotchas
Empty objects.{} and [] both decode to an empty PHP array, and json_encode([]) returns []. Keep empty objects with (object) [] or the JSON_FORCE_OBJECT flag.
Numeric string keys. PHP converts keys like "7" to the integer 7. If such keys happen to be 0, 1, 2 … in order, json_encode() outputs a list instead of an object.
Floats. Since PHP 7.1, json_encode(3.0) gives 3.0, while integers stay integers. Very large integers beyond PHP_INT_MAX become floats.
Escaping. By default PHP escapes slashes (\/) and non-ASCII characters (ë). Use JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE for cleaner output, as this tool does by default.
Frequently asked questions
How are JSON objects represented in PHP?
A JSON object becomes an associative array with string keys, which is what json_decode($json, true) returns. A JSON array becomes a list with keys 0, 1, 2 and so on. If you prefer stdClass objects, as json_decode($json) returns without true, turn on Objects as (object) casts.
What is the difference between [ ] and array( )?
They are identical at runtime. The short [ ] syntax has been available since PHP 5.4 and is the modern standard (PSR-12 and most frameworks use it). Choose array( ) only for very old code bases or style guides that require it.
What does the var_export() style produce?
It reproduces the exact formatting of PHP's var_export($value): array ( with a space, two-space indentation, explicit numeric keys, NULL in capitals, and floats written with a decimal point such as 3.0. This is handy for comparing with output from existing scripts or generated cache files.
How are strings escaped?
Strings are written in single quotes, where only backslash and single quote need escaping, so O'Brien becomes 'O\'Brien'. Strings with line breaks, tabs or other control characters use double quotes with \n, \t and \x escapes, and any $ is escaped so PHP does not try to interpolate variables.
How does PHP array to JSON decide between a list and an object?
It follows json_encode(): an array whose keys are exactly 0, 1, 2 … in order becomes a JSON array, and anything else (string keys, gaps or a different order) becomes a JSON object. Empty arrays become [] unless they are cast with (object) or JSON_FORCE_OBJECT is on. Keys follow PHP rules, so '7' becomes the integer 7, true becomes 1, and a duplicate key overwrites the earlier value.
Can it convert PHP code that uses variables, constants or functions?
No. Only literal values are converted: strings, numbers, true, false, null, nested arrays and (object) casts. Nothing is executed, so expressions like PHP_EOL, $name or date() are reported as errors. Replace them with literal values or run json_encode() in PHP instead.
Is my data uploaded?
No. Both directions are handled by JavaScript in this page and no PHP code is executed, so your data never leaves your device.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.