JSON to PHP Array
Convert JSON to a PHP array literal online, using short [] or long array() syntax. Paste API responses straight into PHP code, tests and config files.
Runs in your browser · Nothing uploadedFree · No sign-up
Something not working, or missing a feature? Send feedback
About the JSON to PHP Array
The JSON to PHP Array converter turns JSON into a PHP array literal you can paste into config files, fixtures and tests, using short [] or long array() syntax.
Conversion happens in your browser, so your files and records stay private.
How to use the JSON to PHP Array
- Paste JSON.
- Choose short [] syntax and whether to wrap the array in <?php return …;.
- Copy the PHP code.
Example
Input
{
"app": { "name": "Shop", "debug": false },
"db": { "host": "localhost", "port": 3306 },
"locales": ["en", "de"],
"motto": "It's fast"
}Result
<?php
return [
'app' => [
'name' => 'Shop',
'debug' => false,
],
'db' => [
'host' => 'localhost',
'port' => 3306,
],
'locales' => [
'en',
'de',
],
'motto' => 'It\'s fast',
];
Objects become associative arrays, the list becomes an indexed array, booleans and numbers keep their types, and the apostrophe is escaped.
Common mistakes
- Expecting objects. The output uses arrays, not stdClass objects. If code needs objects, use json_decode($json) at runtime instead of an array literal.
- Large integers. Integers above PHP_INT_MAX (9223372036854775807) do not fit in a PHP int. Keep such IDs as strings in the JSON.
- Empty objects. An empty JSON object becomes an empty array, which json_encode writes back as [] instead of {}. Use (object) [] where the distinction matters.
Works well with the JSON to PHP Array
- PHP Formatter: format the PHP file the array goes into.
- PHP Compiler: run code that uses the array straight away.
- JSON Validator: fix the JSON first if it does not convert.
Frequently asked questions
How are JSON objects converted?
Objects become associative arrays with string keys; JSON arrays become indexed arrays.
Are special characters escaped?
Yes. Quotes and backslashes in strings are escaped for single-quoted PHP strings.
Which PHP versions can run the output?
Short [] syntax needs PHP 5.4 or newer. Choose long array() syntax for older code bases.
Can I use it for Laravel config files?
Yes. Keep the "<?php return …;" wrapper and save the result in the config folder.
Guides and tutorials
Related tools
JSON to CSV
Convert JSON arrays to CSV online with automatic column detection, nested object flattening and custom delimiters. Open the result in Excel or Sheets.
CSV to JSON
Convert CSV to a JSON array online with header detection, type inference and delimiter auto-detection. Turn spreadsheet exports into data for APIs and code.
JSON to XML
Convert JSON to well-formed XML online with a configurable root element and attribute support. Validate the input and download the XML file.
XML to JSON
Convert XML to JSON online, keeping attributes and turning repeated elements into arrays. Malformed XML is reported with its location.
JSON to YAML
Convert JSON to clean, human-readable YAML online. Turn API responses and package files into config for Kubernetes, Docker Compose or CI pipelines.
YAML to JSON
Convert YAML documents to formatted JSON online with syntax validation. Errors are reported by line, so broken indentation is quick to find and fix.