JSON to PHP Array

Convert JSON into a PHP array.

0 chars
0 words
0 lines
0 chars
0 words
0 lines

JSON to PHP Array Converter

The JSON to PHP array converter turns JSON into a ready-to-paste PHP array literal. Objects become associative arrays, lists become indexed arrays, and every string is safely quoted. Choose modern short [ ] syntax or classic array( ), set the variable name, and copy the code.

Why convert JSON to a PHP array?

PHP projects love arrays: Laravel and Symfony configuration files, WordPress option defaults, test fixtures, seeders, and translation files are all PHP arrays. When the data comes from an API, a JavaScript project, or a design tool as JSON, converting it by hand is slow and error-prone — especially with nested structures and strings containing quotes. This tool does it instantly and correctly.

Conversion rules

  • JSON objects → associative arrays with 'key' => value.
  • JSON arrays → indexed arrays without explicit keys.
  • Integer-like object keys ("0", "42") become integer keys, just like PHP itself would store them.
  • Strings → single-quoted literals with ' and ` escaped, so $` signs are never interpolated.
  • true, false, null, and numbers are written as PHP literals.
  • Every item ends with a trailing comma, which keeps future diffs clean.

Options

  • Syntax – short [ ] arrays (PHP 5.4 and newer) or long array( ) for legacy code.
  • Variable – wraps the array in <?php $config = …;. Leave it empty to get only the literal.
  • Indentation – 4 spaces (PSR-12), 2 spaces, or tabs.

Private conversion

Configuration data often contains hostnames, usernames, and credentials. The conversion runs entirely in your browser, and nothing you paste is uploaded or stored.

Validate the input first with the JSON Validator, or generate other code with JSON to Proto.

Frequently Asked Questions

Objects become associative arrays with 'key' => value pairs, arrays become list arrays, strings become single-quoted PHP strings, numbers stay numbers, true/false stay booleans, and null becomes null — the same result as json_decode($json, true).

You can, but a PHP array literal is faster to load, can be cached by OPcache, supports comments, and is the format Laravel, Symfony, and WordPress use for configuration files and fixtures.

Yes. Strings are written in single quotes, so only single quotes and backslashes need escaping (\' and \\). Dollar signs and other characters are safe because single-quoted PHP strings don't interpolate variables.

You get only the array literal without <?php and assignment, handy for pasting into an existing file — for example after return in a Laravel config file.