Convert JSON into a PHP array literal — short [] or array() syntax, single-quoted escaped strings, the exact structure json_decode($json, true) would produce.
Show calculation steps
Processed privately in your browser — nothing you paste is uploaded, logged or stored.
Static PHP arrays from JSON
WordPress configs, Laravel fixtures, plugin defaults — PHP codebases are full of static data that started life as JSON. This converter produces the exact structure json_decode($json, true) would build, as a literal: JSON objects become associative arrays, JSON arrays become lists, strings are single-quoted with correct escaping, and null/true/false are lowercase keywords.
Worked example
{ "site": "Justwebworld", "active": true, "limits": { "posts": 100 } }becomes:
$data = [
'site' => 'Justwebworld',
'active' => true,
'limits' => [
'posts' => 100,
],
];When to use it
- Config arrays for WordPress and framework projects.
- Database seeders and test fixtures from captured API data.
- Translating a partner’s JSON contract example into PHP defaults.
Limitations to know
- Short [] syntax needs PHP 5.4+ — the array() option exists for genuinely ancient code.
- PHP arrays cannot distinguish an empty object from an empty list; both arrive as [] — the classic asymmetry when encoding back with json_encode.
Common errors and fixes
- Trailing commas — valid PHP and PSR-12 style; leave them.
- Quotes in strings — escaped automatically for single-quoted strings; nothing to fix by hand.
How to use the JSON to PHP Array Converter
- Paste JSON into the input panel.
- Choose short [] or long array() syntax and the variable name.
- Click "Convert to PHP".
- Paste into your PHP source — config files, fixtures, seeders.
Frequently asked questions
What PHP structure does JSON become?
Exactly what json_decode($json, true) produces: JSON objects → associative arrays, JSON arrays → list arrays, null/true/false lowercase. The literal saves you a runtime decode for static data like config and fixtures.
Short [] or long array() syntax?
Short syntax needs PHP 5.4+ (2012) and is the modern standard — use it unless you maintain genuinely ancient code, which is what the long option is for.
How are quotes and special characters escaped?
Strings are single-quoted with backslashes and single quotes escaped — the safest PHP string form, since single quotes do not interpolate variables or interpret escape sequences.
Why a trailing comma after the last element?
It is valid PHP and the convention in modern codebases (PSR-12 formatting tools add it): future additions touch one line, not two.