JSON to PHP array converter

Paste a JSON object or array and copy PHP code you can drop into a config file, a test fixture or a seeder. Objects become associative arrays, arrays become lists, and strings are quoted and escaped for PHP.

Syntax
Indent

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Paste JSON into the box. The sample shows an object with a nested list and object.
  2. Choose the syntax (short [] or long array()), the indent and whether to assign the result to $data.
  3. Copy the PHP code. Invalid JSON shows the line and column of the first error.

How the conversion works

JSON PHP
{“key”: value} [‘key’ => value]
[1, 2] [1, 2] as a list
“text” ‘text’
12, 1.5 12, 1.5
true, false, null true, false, null
{} or [] []

Keys are always quoted strings. Every element gets its own line with a trailing comma, the way var_export() prints arrays.

Worked example

The JSON {"name":"Ada","tags":["math","code"],"ok":true,"x":null} becomes:

$data = [
    'name' => 'Ada',
    'tags' => [
        'math',
        'code',
    ],
    'ok' => true,
    'x' => null,
];

Tips

  • Empty objects become [] in PHP, just as json_decode with true returns an empty array. If you need to keep the difference between {} and [], decode to objects instead.
  • Numeric string keys such as “1” are written as ‘1’; PHP itself turns them into integer keys when the array is created.
  • Large integers beyond 2⁵³ lose precision when JSON is read in JavaScript; keep such IDs as strings in the JSON.

Frequently asked questions

Is the result the same as json_decode($json, true)?

Yes, it has the same shape: JSON objects become associative arrays, JSON arrays become indexed lists, and null, true and false stay as they are. The difference is that you get PHP source code to paste, not a value at run time.

How are strings escaped?

They are written in single quotes, where PHP only treats \\ and \' as escapes. So a backslash becomes \\ and an apostrophe becomes \'. Dollar signs and other characters are kept literally, with no variable interpolation.

Short [] or long array() syntax?

The short syntax works in every PHP version since 5.4 and is the usual choice today. Pick array() only for very old code bases or a style guide that requires it.

Why are there commas after the last items?

Trailing commas are valid in PHP arrays and keep diffs clean when you add a line. var_export() writes them the same way.

What happens to numbers?

They are copied as numbers: 36 stays an integer and 9.5 a float. 1.50 is written as 1.5 and 1e3 as 1000, because the JSON is read as numbers first.

More in Developer

All tools in this category: Developer ·Updated November 7, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.