JSON to PHP Array Converter

Transform JSON data into PHP array syntax with customizable options.

  1. Home
  2. > Web Dev >
  3. JSON to PHP Array
Load Example
0 chars | 0 lines

Settings

0 chars | 0 lines

What is JSON to PHP Array Conversion?

JSON to PHP Array conversion transforms JSON data into native PHP array syntax. This is useful when you need to hardcode configuration data, seeders, or test fixtures directly in PHP code.

This tool features:

  • Custom indentation — Choose between 2 or 4 spaces.
  • Trailing comma — Optionally add trailing commas for cleaner diffs.
  • Short array syntax — Uses [] instead of array().
  • PHP tags included — Output wrapped in <?php return ... ;.
  • Proper escaping — Strings with quotes or backslashes are correctly escaped for PHP single-quoted strings.

How to Use

  1. Paste your JSON — Copy and paste any valid JSON data into the input textarea. You can also click Load Example to load sample data.
  2. Choose settings — Select indentation (2 or 4 spaces) and optionally enable trailing commas.
  3. Convert — Click Convert to PHP to generate the PHP array output.
  4. Copy or download — Use the copy button on the output area or click Download .php to save the result as a file.

Frequently Asked Questions

What PHP array syntax is used?

This tool uses the short array syntax ([]) introduced in PHP 5.4. Keys are automatically detected as numeric (bare integers) or string (single-quoted). Nested objects and arrays are handled recursively.

How are strings escaped?

All strings are wrapped in single quotes. Single quotes within the string are escaped with \' and backslashes are doubled (\\). Unlike double-quoted strings, PHP single-quoted strings do not interpret escape sequences like \n, which makes them safer for literal text.

Is this tool safe for sensitive data?

Yes. All processing happens entirely in your browser using JavaScript. Your JSON data is never uploaded to any server, stored in any database, or logged.

Help2Code Logo
Menu