Skip to main content

PHP Array to JSON Converter

Convert a PHP array literal (array() or [] syntax with => keys, nested arrays, and PHP scalar types) into valid JSON. Choose 2/4-space, tab, or minified output. Runs entirely in your browser.

Input

Output

JSON Output
 
Was this helpful?

Guides

Convert a PHP array literal into clean, valid JSON. Paste code written in either the modern short syntax (['key' => 'value']) or the classic array(...) form, and get back a JSON string you can drop into a config file, an API payload, or a JavaScript project.

What it does

The converter reads PHP array source text and re-expresses it as JSON:

  • Associative arrays ('name' => 'John') become JSON objects.
  • Indexed arrays (array(95, 87, 92)) become JSON arrays.
  • Nested arrays are converted recursively, at any depth.
  • PHP scalars map to their JSON equivalents: single- and double-quoted strings, integers, floats, true/false, and null (keywords are case-insensitive).
  • Mixed arrays — some entries with keys, some without — follow PHP's own rule and give the unkeyed entries the next free integer index.

Choose 2-space, 4-space, tab, or minified output to match your formatting conventions.

How to use it

  1. Paste your PHP array into the input box (with or without a surrounding array( ) or [ ]).
  2. Pick an indentation style.
  3. Copy or download the JSON that appears on the right.

How it works (and why it's safe)

The tool does not run your PHP. It uses a small hand-written tokenizer and parser to read the array literal as text and rebuild it as JSON, so pasted code is only ever inspected, never executed. Everything runs locally in your browser — nothing you paste is uploaded to a server.

What syntax is supported?

Array literals only: array(...), short [...], => key/value pairs, nested arrays, trailing commas, single/double-quoted strings, integers, floats, true, false, and null. Full PHP expressions — function calls, constants, variables, string concatenation, or heredocs — are not evaluated and will report a parse error.

Why did my double-quoted string change?

Inside double-quoted PHP strings the tool applies standard escape handling (\n, \t, \r, \\, \"), so an escape sequence becomes the real character it represents before being encoded into JSON. Single-quoted strings only treat \' and \\ as escapes, exactly like PHP.

Need the reverse?

Use the JSON to PHP Array Converter to turn JSON back into a PHP array literal.

phpjsonarrayconverterdeveloper

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.