PHP Array to JSON Converter

Convert a PHP array literal, written as [...] or array(...), into formatted JSON. String keys become object properties, and arrays whose keys run 0, 1, 2 in order become JSON lists.

1 Paste or type your text

2 Your answer

Your answer shows here as you type.

How to use the PHP Array to JSON Converter

  1. Paste a PHP array into the box, using either [...] or array(...) syntax.
  2. Read the JSON in the output box and copy it.
  3. Keys that run 0, 1, 2 in order become a JSON list; other keys become a JSON object.

Frequently asked questions

What PHP array syntax does this accept?

Both the short form [...] and the long form array(...), with => for keys, nested arrays, single or double quoted strings, numbers, true, false and null. Variables and function calls are not evaluated.

When does a PHP array become a JSON list instead of an object?

When its keys are 0, 1, 2 and so on in order, json_encode outputs a JSON array. Any other key set becomes a JSON object.

Why does PHP json_encode escape forward slashes?

By default json_encode escapes each forward slash with a backslash. Passing the JSON_UNESCAPED_SLASHES flag turns that off. This tool writes plain forward slashes.

Wrote something with AI? Slop Monkey rewrites it so it sounds like you, and keeps your facts.