Developer Tools
JSON to PHP Array Converter
Convert JSON to a PHP array in your browser. Short [...] or array() syntax, single or double quotes, PSR-12 indent, trailing comma, return wrapper.
Output options
Live preview updates with every change. All parsing and emission run in your browser; the JSON you paste is not uploaded.
Array syntax
Short syntax is the modern default. Use long syntax for codebases that target older PHP or follow a house style that prefers it.
String quotes
PHP convention prefers single quotes when no interpolation is needed. Switch to double quotes if your style guide expects them or if you want \n, \t and other C-style escapes preserved.
Indent
PSR-12 (the standard PHP style guide) uses four-space indents. Two spaces match many JavaScript or YAML house styles.
Used when "Assign to variable" is on. Invalid identifier characters are replaced with underscores.
Mapping reference
- JSON object becomes a PHP associative array with the original keys preserved as strings, in the original order (PHP preserves insertion order for arrays).
- JSON array becomes a PHP numeric array (a list) with keys 0..N-1. This matches what json_decode($x, true) would produce on the same input.
- true, false, null map to PHP true, false, and null respectively.
- Numbersstay numeric. JSON does not distinguish integers from floats; PHP does, but its scalar literal syntax is the same as JSON's, so the emitted number always parses back to the value you started with.
- Strings are escaped with PHP rules for the quote style you pick. Single quotes only escape backslashes and the quote itself; double quotes also escape $, \n, \r, \t, and control characters so the literal is byte-for-byte identical to the original.
- Privacy: every step runs in your browser. The JSON you paste is not uploaded.
How to use
- Paste a JSON value into the input on the left, or click Load sample JSON to see a worked example.
- Read the generated PHP on the right. Objects become associative arrays and arrays become numeric lists, exactly matching what json_decode($x, true) would produce.
- Pick the array syntax (short [...] for modern PHP, or array(...) for legacy projects) and the string quote style (single quotes are idiomatic when no interpolation is needed).
- Toggle Prepend <?php to start a fresh .php file, or Wrap in return statement to make the file a drop-in config for require, or Assign to variable for inline use.
- Choose PSR-12 four-space indent or two-space house style, and keep Trailing comma on for cleaner diffs in version control.
- Click Copy PHP to put the full output on your clipboard, ready to paste into a .php file.
About this tool
JSON to PHP Array Converter turns any JSON value into an idiomatic PHP array literal entirely in your browser. Paste an API response, a config file, a fixture, or a copied object literal, and the tool parses it with the browser's native JSON parser, walks the resulting tree, and emits PHP code that matches what json_decode($x, true) would produce on the same input. JSON objects become PHP associative arrays with the original keys preserved as strings, in the original order (PHP arrays preserve insertion order, so the round-trip is exact). JSON arrays become PHP numeric arrays with keys 0..N-1 emitted as a clean list. Booleans, null, and numbers map directly to their PHP equivalents. Strings are escaped with the correct rules for the quote style you pick: single quotes only need to escape backslashes and the quote itself, while double quotes also escape $ (so the literal cannot be interpolated by accident), plus \n, \r, \t, \v, \f, \e, and any other control characters so the literal is byte-for-byte identical to the original. Output options give full control over the resulting code: short [...] syntax (the modern PHP 5.4+ default) or legacy array(...) syntax for older codebases, four-space PSR-12 indentation or two-space house style, single or double string quotes, an optional <?php tag for files that will be saved fresh, an optional $variable = ... assignment with a sanitized identifier, an optional return statement so the file becomes a drop-in config for require_once or service container loaders, and an optional trailing comma after the last element of multi-line arrays for cleaner diffs (a PHP best practice). Object keys that look like canonical PHP integers are emitted as integer keys instead of strings, so json_decode($x, true) round-trips perfectly. Useful for porting JSON fixtures into PHPUnit data providers, dropping API examples into Laravel or Symfony config files, building seed data for Eloquent or Doctrine, scaffolding language and localization files, generating cached PHP arrays from JSON snapshots, and turning third-party schema dumps into editable PHP code. Parsing and emission run locally on your device, so the JSON you paste here never leaves your browser.
Free to use. Works in your browser. No signup, no login.
Related tools
You may also like
JSON to TypeScript Converter
Generate TypeScript interfaces or types from any JSON value with full inference.
Open tool
DeveloperJSON to Go Struct Converter
Generate idiomatic Go structs with json tags from any JSON value.
Open tool
DeveloperJSON Formatter
Format, minify, and validate JSON in your browser.
Open tool
DeveloperJSON Tree Viewer
Collapsible JSON tree with search, JSONPath, type icons, and copy-by-node.
Open tool
DeveloperJSON Schema Generator
Infer a JSON Schema document (Draft 7 or 2020-12) from any JSON value.
Open tool