JSON to PHP Array Converter
Converts JSON into a PHP array literal you can paste straight into source, and reads PHP array literals back into JSON. Booleans become true and false, null stays null, and strings are single-quoted with the necessary escaping applied.
It is the quickest way to turn an API response into a fixture, a configuration file or a test double.
How to use it
- Paste JSON on the left to produce a PHP array literal.
- Press Swap to read an existing PHP array back into JSON.
- Both the modern [ ... ] syntax and the older array( ... ) form are accepted.
Lists and associative arrays are not the same thing
PHP uses square brackets for both a list and a map, so ['a' => 1] is a JSON object while [1, 2] is a JSON array. Only the presence of => tells them apart, which is why the input is properly parsed rather than pattern-substituted — a search-and-replace approach gets this wrong every time.
The parser also tolerates trailing commas, // # and /* */ comments, a leading <?php, and a leading return, so you can paste a config file fragment as you found it.
Frequently asked questions
Does it handle the old array() syntax?
- Yes. Both array('a' => 1) and ['a' => 1] parse identically.
Will a PHP list become a JSON array?
- Yes. An array with no => keys becomes a JSON array; one with keys becomes a JSON object. Mixed arrays keep their positional entries under their implicit numeric indices.
Can it read arbitrary PHP code?
- No, only array literals. Function calls, variables and expressions cannot be evaluated without running PHP, so they are reported as unreadable rather than guessed at.