JSON to PHP Array Converter
Convert JSON into a ready-to-paste PHP array literal — objects become 'key' => value associative arrays, arrays become list arrays, with short [] or legacy array() syntax, your choice of indentation, and an optional $variable / <?php wrapper. Runs entirely in your browser.
Input
Short [] (PHP 5.4+) or the legacy array() form.
Emit the bare array, a variable assignment, or a full <?php block.
Output
Guides
Turn any JSON document into a clean, ready-to-paste PHP array literal. Paste an object or array, pick your formatting, and copy the result straight into a .php file. The converter maps JSON structures onto their natural PHP equivalents: objects become associative arrays using 'key' => value syntax, arrays become plain list arrays, and scalars map to real PHP literals — true, false, null, unquoted numbers, and single-quoted strings.
It is a pure text transformer. It reads your JSON and writes PHP source code — it never runs PHP and never sends your data anywhere.
How to use it
- Paste or type your JSON into the input box.
- Choose the array syntax: modern short
[ ](PHP 5.4+) or the legacyarray( )form for older codebases. - Choose the indentation: 2 spaces, 4 spaces, or tabs.
- Optionally choose an output wrapper — the bare array literal, a
$variable = [ … ];assignment, or a complete<?phpblock — and name the variable. - Copy the generated PHP, or download it as a
.phpfile.
The output updates automatically as you type or change an option.
How are strings escaped?
Strings are emitted as PHP single-quoted literals. Inside a single-quoted PHP string only two characters are special: the backslash (\) and the single quote ('). The converter escapes exactly those, so a value like O'Brien becomes 'O\'Brien' and a Windows path C:\Users becomes 'C:\\Users'. Everything else — including sequences like \n or \t — is left untouched, which is precisely how PHP treats them in a single-quoted string (as literal characters, not newlines or tabs).
What happens to numbers, booleans, and null?
They become unquoted PHP literals: JSON true/false/null map directly to PHP true/false/null, and numbers are written as-is (30, 3.14). They are never wrapped in quotes, so they stay as real integers, floats, and constants in your array.
Short [] vs. legacy array() — which should I pick?
Use short [ ] for any project on PHP 5.4 or newer — it is the modern standard and easier to read. Choose array( ) only when you need compatibility with very old PHP or a codebase whose style guide still requires it. Both produce identical data; only the surrounding syntax differs.
Can I convert a top-level JSON array or a single value?
Yes. A top-level array produces a PHP list array with no keys, and a lone string, number, boolean, or null produces the matching PHP literal. Nested objects and arrays are converted recursively to any depth.
Is my data private?
Yes. The entire conversion runs client-side in your browser — your JSON is never uploaded, logged, or stored. You can even use it offline once the page has loaded, which makes it safe for configuration data and other sensitive payloads.