JSON ⇄ PHP Array Converter

Client-sideNo sign-upFree

Convert JSON to PHP array syntax or PHP array syntax to JSON, in either direction, in your browser.

Quick facts

Category
Converters
Best for
Moving fixture or config data between a JS/JSON codebase and a PHP one
JSON
PHP array
[ 'name' => 'Formatiq', 'active' => true, 'tags' => [ 'json', 'php', ], 'meta' => [ 'version' => 1, 'deprecated' => null, ], ]
✓ Converted
PHP output uses short array syntax ([...]) with single-quoted string keys, matching modern PHP style (var_export()-like but not identical to its exact output format). A PHP array with sequential integer keys starting at 0 converts to a JSON array; anything else (string keys, or out-of-order integer keys) becomes a JSON object, matching how PHP's own json_encode() treats arrays.
In-content slot
Was this tool helpful?
On this page

Overview

Convert JSON into PHP array literal syntax, or a PHP array literal back into JSON, using a small purpose-built tokenizer and parser rather than a regex substitution - regex can’t reliably handle nested arrays, quoted strings containing commas or brackets, or PHP’s "=>" key syntax, so this walks the actual token structure instead. PHP output uses modern short array syntax ([...]) with single-quoted string keys; a PHP array with sequential integer keys starting at 0 converts to a JSON array, while string keys or out-of-order integer keys convert to a JSON object, matching how PHP’s own json_encode() treats arrays. Useful for moving config or fixture data between a JS/JSON codebase and a PHP one, or reading a PHP array literal from a legacy config file as JSON. Runs entirely client-side.

Best for: Moving fixture or config data between a JS/JSON codebase and a PHP one

How to use this tool

  1. Pick a direction. Switch between JSON → PHP and PHP → JSON with one click.
  2. Paste your input. Drop in a JSON object/array or a PHP array literal.
  3. Read the converted output. Sequential arrays and associative arrays are distinguished automatically, matching PHP’s own conventions.
  4. Swap and repeat. Use the swap button to feed the output straight back in as new input.

Why use this tool

Real parsing, not regex

A small tokenizer and parser handle nested arrays and quoted strings correctly, which a regex-based approach can’t do reliably.

Matches PHP’s array/object convention

Sequential integer-keyed arrays become JSON arrays; everything else becomes a JSON object, the same rule PHP’s json_encode() uses.

Modern short array syntax

JSON → PHP output uses [...] rather than the older array(...) form, matching current PHP style.

Nothing leaves your browser

Conversion happens entirely client-side - useful when the data includes real config values or fixture data.

Frequently asked questions

Yes for parsing PHP → JSON - both array(...) and [...] are accepted as input. JSON → PHP output always uses the modern short [...] syntax, since that’s the current PHP style recommendation.

A PHP array with sequential integer keys starting at 0 (whether those keys are explicit or just implied by position) converts to a JSON array. Any array with string keys, or with integer keys that skip a number or start somewhere other than 0, converts to a JSON object instead - the same rule PHP’s built-in json_encode() function uses.

No - this only handles plain array literals: strings, numbers, true/false/null, and nested arrays. PHP objects, closures, constants, and variables aren’t valid inside a plain array literal in the way this parser expects, and won’t convert.

Explore more free tools

Formatters, converters, validators, and generators - all free and running entirely in your browser.

Browse more tools