JSON to PHP Array Converter
Paste JSON on the left to get a clean PHP array, or paste a PHP array ([...] or array(...)) on the right to get JSON. The PHP to JSON output matched PHP's own json_encode() in our tests.
FreeNo sign-upRuns in your browser: your data is not uploaded
When you need it
- Config files: an API sends its settings as JSON and you want them in
config/services.php. - Tests and seeders: copy a real API response from the browser's Network tab, convert it, and paste it as a fixture or
Http::fake()body. - Debugging: turn a
var_export()orprint_r-style array from a log back into JSON to read it in a JSON viewer or send it to a colleague.
Things the converter handles for you
- Quotes and backslashes in strings are escaped for PHP single quotes (
'it\'s'). - Numeric JSON keys become integer keys (
10 => 'ten'), as PHP itself would store them. - PHP input may use
[]orarray(), single or double quotes, trailing commas, comments,1_000number separators, and may start with<?php,returnor$config =. - Arrays with keys in any order keep that order in the JSON, so the output matches
json_encode().
What it cannot convert
Anything that only exists when PHP runs: variables ("Hello $name"), function calls like env('APP_URL') or now(), and objects. Constants such as PDO::ATTR_ERRMODE are kept as text. Replace those parts with their values first, or convert only the static part.
Doing it in PHP itself
If you have PHP at hand: var_export(json_decode($json, true)); prints an array (in the older array(...) style), and json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) goes the other way. This page gives you the short syntax and proper indentation without a PHP shell.
FAQ
Why do I get an empty array [] instead of {} in JSON?
json_encode() writes it as [], so this tool does the same. Use new stdClass or JSON_FORCE_OBJECT in PHP if you need {}.Does json_decode() give an array or an object?
json_decode($json) gives objects (stdClass); json_decode($json, true) gives associative arrays, which is what this converter produces.Is my JSON sent to a server?
Why does "PHP to JSON" fail on my file?
env(), or more than one statement. The error shows the part it stopped at.Related guides
Link to this tool
Found it useful? Put a link in your docs, README or forum answer so others can use it too:
<a href="https://headsntail.com/tools/json-to-php-array">JSON to PHP Array Converter (and back)</a> (free, by HeadsNTail)
[JSON to PHP Array Converter (and back)](https://headsntail.com/tools/json-to-php-array)
Share: X LinkedIn Reddit WhatsApp
Need it done on your server? HeadsNTail sets up Laravel apps, cPanel hosting and migrations for businesses. See services or ask a question.