Skip to content
gohacks.dev
Standard Library

JSON to PHP Array

Convert JSON into a PHP array literal with short [] syntax, ready to paste into a Laravel config file, a seeder or a test.

Free · No sign-up · Your inputs stay in your browser

Input

Convert JSON to a PHP array

Output

PHP

491 characters

Strings are single-quoted, so $ and \n inside them stay literal, matching what json_decode($json, true) would give you at runtime. Laravel config files and seeders use exactly this shape.

Runs in this browser. Nothing you paste is sent to a server.

Same data as json_decode()

The output is what json_decode($json, true) returns at runtime, written out as source. Integer-looking object keys such as "1" become integer keys, as PHP does with any numeric string key. Without true, json_decode() returns stdClass objects instead; config files and seeders want arrays.

Where this is handy

Laravel config files return a PHP array, factories and seeders define rows as arrays, and test fixtures are easier to read as PHP than as an embedded JSON string. For large fixtures, keep the JSON in a file and decode it in the test instead: json_decode(file_get_contents(__DIR__.'/fixture.json'), true).

Share

Frequently asked questions

Why single quotes in the output?
PHP does not expand $ or escape sequences in single-quoted strings, so the value is exactly the JSON string, with no risk of a $ being read as a variable.
Can it convert a PHP array back to JSON?
Not here. In PHP, json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) does it.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools