1001Ferramentas
🐘 Converters

JSON to PHP Array

Convert JSON to a PHP array in "short" (`[]`) or "long" (`array()`) syntax. Useful to generate config and seed files in Laravel/Symfony projects. Everything in your browser.

Turn an API payload into a config file

You have a JSON blob on hand, an API response, a fixture, a snippet from some docs, and you need it as a PHP array inside config/ or a seeder. Doing it by hand means swapping colons for arrows, fixing quotes, and finding the syntax error only when Artisan complains. This converter hands back the finished file, opening tag and return statement included.

Input goes through the browser's own JSON parser and the output is built recursively. A JSON array becomes a PHP list with no written indexes, an object becomes an associative array with quoted keys and arrows. Strings come out single quoted, escaping only backslash and the quote itself, which is exactly what PHP single quotes require: no accidental dollar sign interpolation. The selector at the top switches between short brackets and the older array parenthesis form.

Two things are worth checking. Very large integers, past nine quadrillion, lose precision inside the JSON parser itself, so long IDs should be strings at the source. And a numeric string key turns into an int when PHP builds the array, which can scramble a code lookup map. The generated file is a literal, with no json_decode at runtime, so it is faster and cacheable. Conversion happens in your browser and the JSON never leaves your machine.

Frequently asked questions

Short brackets or array()?
Short brackets have been standard since PHP 5.4 and are what nearly every new project uses. The long form only makes sense if your team style guide asks for it or you target something very old.
Does the output include json_decode?
No. It emits the array literal after a return statement, the shape Laravel and Symfony expect from a config file. Nothing is parsed at runtime.
Will single quotes break my text?
No. Backslashes and apostrophes are escaped before they go into the string. As a bonus, single quotes do not interpolate variables, which is the correct behaviour for data.

Related Tools