JSON to PHP Array
Convert JSON into an equivalent PHP array literal, ready to paste directly into PHP code.
Paste JSON below - this tool converts it into an equivalent PHP array literal you can paste directly into your code.
More Programming Language Tools
View all 23Going the other direction? Use the PHP Array to JSON converter instead.
What Does This Tool Do?
It parses JSON and generates the equivalent PHP array literal using the modern short array syntax (['key' => 'value']), correctly handling nested objects and arrays.
Why Use This Tool?
Useful when you have a JSON API response or config file and want to hardcode the equivalent data directly as a PHP array - for a test fixture, a config file, or a quick script.
How to Use It
- Paste valid JSON.
- Click Convert.
- Copy the generated PHP array code.
Limitations
JSON's data types (string, number, boolean, null, array, object) map directly to PHP equivalents - there's no ambiguity in this direction, unlike JSON-to-typed-language conversions that need to infer types.
Example
{"name": "Blue Mug", "price": 249, "in_stock": true, "tags": ["kitchen", "gift"], "discount": null}
becomes:
$data = [
'name' => 'Blue Mug',
'price' => 249,
'in_stock' => true,
'tags' => [
'kitchen',
'gift',
],
'discount' => null,
];
Where It Helps
- Laravel and Symfony config files, which return PHP arrays.
- PHPUnit or Pest tests - paste an API response as expected data.
- Seeders and factories that need realistic sample records.
Alternative: Decode at Runtime
If the JSON changes often or is large, keep it as a file and decode it instead:
$data = json_decode(file_get_contents(__DIR__.'/data.json'), true, flags: JSON_THROW_ON_ERROR);
The true argument returns arrays rather than objects. A hard-coded array is better for small, stable data that you want to read and edit in PHP.
Convert back with PHP Array to JSON, and tidy the file with the PHP Formatter.
Frequently Asked Questions
Explore More Tools
Keep going with related categories and our most used tools.