ToolLineup

JSON to PHP Array Converter

This converter turns JSON into a PHP array literal you can paste straight into a config file, a fixture or a seed script. Strings are escaped correctly, so an apostrophe in the data cannot break the literal — which is the one thing that makes hand-conversion tedious and error-prone. The short bracket syntax is used by default, with the older array() form available for code that still has to run on PHP 5.3. Naming a variable wraps the result in a complete PHP file with an opening tag, ready to include, rather than a bare expression you would have to assign yourself.

How it works

Converts JSON into a PHP array literal you can paste straight into a config file, a fixture or a seed script. Strings are escaped properly, so an apostrophe in the data cannot break the literal.

The short [] syntax is used by default; switch to array() if you are targeting PHP 5.3 or earlier. Naming a variable wraps the result in a complete PHP file ready to include.

Everything runs in your browser — nothing you paste is sent to a server.

JSON input
Paste your JSON here…
PHP array

When you want code, not a decode

If the JSON is data your program fetches, json_decode is the right answer. This tool is for the other case: when the data belongs in the source, as a config array, a fixture, a lookup table or a set of defaults.

Writing that by hand is where the mistakes creep in — a missed comma, an unescaped apostrophe in a name — which is exactly the tedium worth automating.

Escaping

PHP single-quoted strings escape only two things: the backslash and the single quote itself. Both are handled, so a value such as O'Brien or a Windows path comes out correct.

Keys

JSON object keys become string keys and arrays become PHP lists with implicit numeric keys — which is the correct mapping, since PHP has one array type where JSON has two.

Frequently asked questions

How do I convert JSON to a PHP array?

Paste your JSON into the left panel. The PHP array literal appears on the right, ready to copy.

Why not just use json_decode?

For runtime data, do. This is for when you want the data as literal code — a config file, a fixture, a lookup table — where a decode at runtime would be wasted work.

Are quotes escaped?

Yes. Single quotes and backslashes inside strings are escaped, so a value like O'Brien cannot break the literal.

What is the difference between [] and array()?

They are identical in behaviour. The short [] syntax needs PHP 5.4 or later; array() works everywhere, which matters only for very old codebases.

What happens to null?

It becomes PHP null. Booleans become true and false, and numbers stay numbers.

Is my data uploaded?

No. The conversion runs entirely in your browser.

Related tools