WebToolsPlanet
Converter Tools

JSON to PHP Array Converter

Paste JSON and get a ready-to-paste PHP array literal — pick short or long syntax, optionally wrap it in a `$variable = ...;` assignment.

Last updated: May 27, 2026

Client-Side Processing
Input Data Stays on Device
Instant Local Execution

Find this tool useful? Support the project to keep it free!

Buy me a coffee

What is JSON to PHP Array Converter?

PHP has its own array literal syntax. Modern PHP (5.4+) uses square brackets — `['key' => 'value']` — and older code uses the `array(...)` function form. JSON is structurally similar to PHP associative arrays, so converting is mechanical: object keys become string keys, arrays stay arrays, and primitives map onto PHP's scalars.

The tricky parts are string escaping and the choice of literal form. This tool emits single-quoted PHP strings (which don't interpolate variables and only require escaping `\` and `'`) and lets you pick between short and long syntax. You can optionally wrap the result in a variable assignment so it's a complete statement ready to drop into a script.

How to Use JSON to PHP Array Converter

1

Paste JSON into the input panel.

2

Pick short [ ] or long array( ) syntax.

3

Optionally enter a variable name to produce `$name = ...;` output.

4

Adjust indent and semicolon options.

5

Copy the PHP array literal.

Common Use Cases

  • Importing a JSON fixture into a PHP test or seed file.
  • Embedding configuration values from a JSON file into PHP source code.
  • Producing a PHP array literal for a translation table or a lookup map.
  • Migrating between a JSON-based and PHP-array-based configuration format.

Example Input and Output

A flat JSON object becomes a short-syntax PHP array with a variable assignment.

JSON input
{ "name": "Alice", "age": 30, "active": true }
PHP output
$user = [
    'name' => 'Alice',
    'age' => 30,
    'active' => true,
];

Privacy

All conversion happens in your browser. No JSON is sent to a server.

Compatibility

Short array syntax requires PHP 5.4 or later. For legacy PHP environments, switch to long array( ) syntax.

Frequently Asked Questions

Why single-quoted strings?
Single-quoted PHP strings do not interpolate variables or process most escapes — they are the safe default for literal data. You only need to escape \\ and ' in the contents.
What about nested objects and arrays?
Both are handled recursively. JSON objects become PHP associative arrays with string keys; JSON arrays become PHP indexed arrays.
Why does the output have a trailing comma?
PHP allows trailing commas in array literals, and they keep diffs clean when you add or remove items. Disable the trailing semicolon checkbox only — there is no toggle for the comma since it harms nothing.
Does this send my JSON anywhere?
No. All conversion happens locally in your browser.