Skip to content
Devtoolry

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

  1. Paste JSON.
  2. Choose short [] syntax and whether to wrap the array in <?php return …;.
  3. Copy the PHP code.

Example

Create a PHP config array

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

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