JSON to PHP Array
JSON to PHP Array Generator
Paste a JSON object or array and get a PHP variable assignment with the correct associative array syntax. JSON null stays null, true/false stay lowercase, and nested objects become nested associative arrays. Works with Laravel, Symfony, WordPress, and plain PHP. Runs entirely in your browser.
Where Is This Useful?
json_decode() at test time.How to Use
- Paste a JSON object or array in the input panel
- Set a variable name (defaults to data)
- Click Convert to PHP or press Ctrl+Enter
- Copy the PHP code or download as a
.phpfile
Type Mapping
- JSON
null→ PHPnull - JSON
true/false→ PHPtrue/false - JSON integer → PHP
int - JSON float → PHP
float - JSON string → PHP single-quoted string
- JSON object → PHP
['key' => 'value']associative array - JSON array → PHP indexed
['a', 'b', 'c']array
Frequently Asked Questions
What PHP syntax does this generate?
Modern short array syntax [] with => for associative pairs. The output includes a <?php tag and a $variable = [...]; assignment.
Is this compatible with PHP 7 and 8?
Yes. The [] short array syntax has been available since PHP 5.4 and works in all modern PHP versions.
Can I paste this into Laravel or Symfony?
Yes. The output is standard PHP that works in any framework. For Laravel config files, just use the array directly inside a return [...]; statement.
How are special characters in strings handled?
Backslashes and single quotes inside strings are escaped with a backslash. All strings use single-quote delimiters.
Is my JSON uploaded anywhere?
No. Everything runs locally in your browser. Your data never leaves your machine.
Related Tools