JSON to PHP Array Converter
Paste JSON and get a ready-to-paste PHP array literal with correct nesting and types. JSON objects become associative arrays with 'key' => value pairs, JSON arrays become indexed arrays with values only, and every string is single-quoted with backslashes and quotes escaped. Toggle between the classic array() form and short [] syntax, and pick a 2 or 4 space indent.
How to convert JSON to a PHP array
- Paste or type your JSON into the JSON input box, or click Load sample to try it.
- Tick 'Short syntax [ ]' to emit square brackets, or leave it off for array().
- Set the Indent dropdown to 2 spaces or 4 spaces.
- Watch the PHP array box update as you type; a red message appears if the JSON is invalid.
- Click Copy and paste the literal straight into your PHP source.
Examples
Object with a nested array (array syntax)
{"name":"Ada","tags":["dev","math"]}array(
'name' => 'Ada',
'tags' => array(
'dev',
'math',
),
)Booleans, numbers and nesting (short syntax)
{"active":true,"score":3.5,"meta":{"id":7}}[
'active' => true,
'score' => 3.5,
'meta' => [
'id' => 7,
],
]Empty array and empty object collapse
{"items":[],"config":{}}array( 'items' => array(), 'config' => array(), )
Frequently asked questions
Is my JSON uploaded anywhere?
No. The conversion runs entirely in your browser with JavaScript, so your data never touches a server and nothing is stored.
What is the difference between array() and short syntax?
They produce identical arrays in PHP 5.4 and later. Short syntax swaps array( and ) for [ and ], which many modern style guides such as PSR prefer for brevity.
How are JSON objects and arrays mapped?
JSON objects become associative PHP arrays written as 'key' => value. JSON arrays become indexed arrays that list values only, with no explicit keys, matching PHP's default zero-based indexing.
How are strings escaped?
Every string is wrapped in single quotes. Inside, a backslash becomes two backslashes and a single quote is prefixed with a backslash, which is exactly what a PHP single-quoted literal requires. Other characters, including double quotes, are left as-is.
How are true, false and null handled?
They map to the lowercase PHP keywords true, false and null. Numbers are printed exactly as they appear in the JSON, so 3.5 and 42 stay the same and are not quoted.
What happens to an empty object or empty array?
Both collapse to an empty literal on one line, either array() or [] depending on your syntax choice, because there are no entries to indent.
Are object keys and array indexes preserved in order?
Yes. Keys are emitted in the same order they appear in your JSON object, and array items keep their original sequence, so the PHP output mirrors the input structure.
Does it validate my JSON?
Yes. If the input is not valid JSON, the tool shows the parser's error message instead of output, so you can spot a trailing comma or a missing quote quickly.
Can I convert PHP arrays back to JSON here?
No, this tool only goes from JSON to PHP. In PHP itself you can reverse the process with json_encode() on the array to produce JSON again.
Learn more
- PHP array syntax when converting from JSON
How JSON objects, arrays, strings and scalars translate into PHP array literals, and why single quotes and short syntax matter.
Related tools
JSON to Python Dict
Convert JSON to a Python dict online. Paste JSON and get a valid dict and list literal with True, False, None and proper quoting. Runs in your browser.
JSON to CSV
Convert JSON to CSV online. Paste an array of objects and get clean, spreadsheet-ready CSV with the right headers. Runs in your browser.
JSON Formatter
Format, validate and minify JSON online. Pretty-print with custom indentation, sort keys and catch syntax errors. Runs in your browser.
Air Fryer Converter
Convert any conventional oven recipe to air fryer settings. Lower the temperature by 25 F and cut the cook time by about 20 percent automatically.
Baker's Percentage Calculator
Turn a bread formula into grams with baker's percentages. Flour is 100 percent, enter water, salt and yeast percents to get weights and hydration.
Baking Pan Converter
Swap one baking pan for another and scale the batter to fit. Compares pan areas for round, square and rectangular pans and gives a batter scale factor.