About the JSON to PHP Array
Convert JSON into PHP array code with short array syntax, properly escaped strings and nested arrays.
Key features
- Modern short array syntax [] with => notation
- Properly escaped single-quoted strings
- Nested arrays indented for readability
- true/false/null mapped to PHP literals
- Output wrapped in a ready-to-use <?php file
- Download as data.php
Convert JSON into PHP code
PHP projects are full of array-based configuration: Laravel's config/*.php, Symfony bundles, WordPress plugin settings, database seeders, test fixtures and translation files. When your data starts life as JSON, from an API, a design tool or another service, converting it to a PHP array literal saves tedious manual rewriting.
Example
{
"app": "XUtilHub",
"debug": false,
"features": ["json", "pdf"],
"mail": { "host": "smtp.example.com", "port": 587 }
}
<?php
$data = [
'app' => 'XUtilHub',
'debug' => false,
'features' => [
'json',
'pdf',
],
'mail' => [
'host' => 'smtp.example.com',
'port' => 587,
],
];
Mapping
| JSON | PHP |
|---|---|
{"k": v} | ['k' => v] |
[1, 2] | [1, 2] |
"text" | 'text' |
true / false | true / false |
null | null |
3.5 | 3.5 |
Laravel config example
Save the output as config/services_extra.php, replace $data = with return, and access values with config('services_extra.mail.host').
json_decode vs. a PHP array literal
json_decode($json, true) | Array literal | |
|---|---|---|
| Data changes at runtime | ✅ | ❌ |
| Opcache-friendly config | ⚠️ parse on every request | ✅ |
| Readable in code review | ⚠️ | ✅ |
| Supports comments | ❌ | ✅ |
Related tools
Generating Java instead? See JSON to Java. Need a string literal for PHP? JSON to String has a PHP mode.
How to use the JSON to PHP Array
- Paste your data into the input box, upload a file, or click Sample to try it out.
- Adjust the options above the editor if you need to (indentation, delimiter, and so on).
- The PHP Array appears instantly in the output panel. Any errors are shown with their line and column.
- Click Copy to copy the result, or Download to save it as a file.