JSON to PHP Array

FreePrivateInstant
JSON input
PHP output
Ctrl+Enter Convert to PHP

JSON to PHP Array Generator

Paste a JSON object or array and get a PHP variable assignment with the correct associative array syntax. JSON null stays null, true/false stay lowercase, and nested objects become nested associative arrays. Works with Laravel, Symfony, WordPress, and plain PHP. Runs entirely in your browser.

Where Is This Useful?

Config arrays in PHP
Laravel config files, WordPress settings, and Symfony parameter files are PHP arrays. Convert your JSON config to a PHP array format to paste directly into a config file without manual conversion.
Test fixtures and seeds
Writing PHPUnit tests or database seeders? Convert a JSON fixture to a PHP array to use as hardcoded test data without needing to call json_decode() at test time.
API response inspection
Got an API response in JSON and want to understand its structure as a PHP variable? Convert it here and paste it into a PHP script or debugger to inspect the shape and values.

How to Use

  1. Paste a JSON object or array in the input panel
  2. Set a variable name (defaults to data)
  3. Click Convert to PHP or press Ctrl+Enter
  4. Copy the PHP code or download as a .php file

Type Mapping

  • JSON null → PHP null
  • JSON true/false → PHP true/false
  • JSON integer → PHP int
  • JSON float → PHP float
  • JSON string → PHP single-quoted string
  • JSON object → PHP ['key' => 'value'] associative array
  • JSON array → PHP indexed ['a', 'b', 'c'] array

Frequently Asked Questions

What PHP syntax does this generate?

Modern short array syntax [] with => for associative pairs. The output includes a <?php tag and a $variable = [...]; assignment.

Is this compatible with PHP 7 and 8?

Yes. The [] short array syntax has been available since PHP 5.4 and works in all modern PHP versions.

Can I paste this into Laravel or Symfony?

Yes. The output is standard PHP that works in any framework. For Laravel config files, just use the array directly inside a return [...]; statement.

How are special characters in strings handled?

Backslashes and single quotes inside strings are escaped with a backslash. All strings use single-quote delimiters.

Is my JSON uploaded anywhere?

No. Everything runs locally in your browser. Your data never leaves your machine.

Related Tools