Boneyard Tools

JSON to PHP Array Converter

Paste JSON and get a ready-to-paste PHP array literal with correct nesting and types. JSON objects become associative arrays with 'key' => value pairs, JSON arrays become indexed arrays with values only, and every string is single-quoted with backslashes and quotes escaped. Toggle between the classic array() form and short [] syntax, and pick a 2 or 4 space indent.

How to convert JSON to a PHP array

  1. Paste or type your JSON into the JSON input box, or click Load sample to try it.
  2. Tick 'Short syntax [ ]' to emit square brackets, or leave it off for array().
  3. Set the Indent dropdown to 2 spaces or 4 spaces.
  4. Watch the PHP array box update as you type; a red message appears if the JSON is invalid.
  5. Click Copy and paste the literal straight into your PHP source.

Examples

Object with a nested array (array syntax)

{"name":"Ada","tags":["dev","math"]}
array(
  'name' => 'Ada',
  'tags' => array(
    'dev',
    'math',
  ),
)

Booleans, numbers and nesting (short syntax)

{"active":true,"score":3.5,"meta":{"id":7}}
[
  'active' => true,
  'score' => 3.5,
  'meta' => [
    'id' => 7,
  ],
]

Empty array and empty object collapse

{"items":[],"config":{}}
array(
  'items' => array(),
  'config' => array(),
)

Frequently asked questions

Is my JSON uploaded anywhere?

No. The conversion runs entirely in your browser with JavaScript, so your data never touches a server and nothing is stored.

What is the difference between array() and short syntax?

They produce identical arrays in PHP 5.4 and later. Short syntax swaps array( and ) for [ and ], which many modern style guides such as PSR prefer for brevity.

How are JSON objects and arrays mapped?

JSON objects become associative PHP arrays written as 'key' => value. JSON arrays become indexed arrays that list values only, with no explicit keys, matching PHP's default zero-based indexing.

How are strings escaped?

Every string is wrapped in single quotes. Inside, a backslash becomes two backslashes and a single quote is prefixed with a backslash, which is exactly what a PHP single-quoted literal requires. Other characters, including double quotes, are left as-is.

How are true, false and null handled?

They map to the lowercase PHP keywords true, false and null. Numbers are printed exactly as they appear in the JSON, so 3.5 and 42 stay the same and are not quoted.

What happens to an empty object or empty array?

Both collapse to an empty literal on one line, either array() or [] depending on your syntax choice, because there are no entries to indent.

Are object keys and array indexes preserved in order?

Yes. Keys are emitted in the same order they appear in your JSON object, and array items keep their original sequence, so the PHP output mirrors the input structure.

Does it validate my JSON?

Yes. If the input is not valid JSON, the tool shows the parser's error message instead of output, so you can spot a trailing comma or a missing quote quickly.

Can I convert PHP arrays back to JSON here?

No, this tool only goes from JSON to PHP. In PHP itself you can reverse the process with json_encode() on the array to produce JSON again.

Learn more

Related tools