$var = and <?php.Ready to convert
Paste a PHP array and click Convert// convert php arrays to clean json instantly
Convert PHP arrays and nested structures to valid JSON instantly. Supports associative arrays, indexed arrays, and complex nested data — browser-based and free.
$var = and <?php.Ready to convert
Paste a PHP array and click ConvertPaste any PHP array — with or without $var = or <?php. Indexed, associative, and nested arrays all work.
Select "Pretty Print" for human-readable JSON with indentation, or "Minified" for compact single-line output.
Click "Convert to JSON", then copy the result to clipboard or download it as a .json file.
This tool converts PHP array syntax into valid JSON. PHP uses => for key-value pairs and [] or array() notation, while JSON uses : and mandates double-quoted string keys. This converter handles the translation automatically, including type mapping for booleans, null, integers, and floats.
Both modern bracket syntax ['key' => 'value'] and classic array('key' => 'value') notation are supported. You can include or omit the variable assignment ($data =) and PHP opening tag (<?php).
Yes. Deeply nested associative and indexed arrays convert correctly. PHP nested arrays become nested JSON objects or arrays as appropriate depending on their key types.
Pretty Print adds indentation and line breaks for readability, ideal for development and debugging. Minified output removes all unnecessary whitespace to produce a compact representation suited for production use.
Basic literal values (strings, integers, floats, booleans, null) are supported. PHP-defined constants like PHP_EOL or expressions using external functions are not evaluated for security reasons.
The conversion uses strict security filters to block dangerous PHP functions. That said, we recommend never pasting production credentials or personally identifiable information into any online tool.
PHP true becomes JSON true, false becomes false, and null becomes null. These are standard type equivalents across both languages.
PHP arrays with sequential integer keys (0, 1, 2…) convert to JSON arrays []. Arrays with string keys or non-sequential integer keys become JSON objects {}.
This tool converts one direction: PHP to JSON. For the reverse, in PHP you can use json_decode($json, true) to get an associative array back from a JSON string.
Converting PHP arrays to JSON is one of the most common tasks in modern web development. Whether you are migrating legacy PHP applications to RESTful APIs, sharing configuration data with JavaScript frontends, or exporting structured data to other services, transforming PHP array syntax into valid JSON is a daily workflow for PHP developers.
Our PHP Array to JSON converter handles the full spectrum of PHP array types — from simple indexed arrays and associative key-value pairs to deeply nested multi-dimensional structures — and produces clean, spec-compliant JSON in seconds, right in your browser.
PHP and JSON both represent structured data, but with distinct syntax. A PHP associative array uses the => operator and wraps key-value pairs in square brackets or array() calls. JSON uses : for key-value pairs and mandates double-quoted string keys throughout.
For example, the PHP array ['name' => 'Alice', 'age' => 28, 'active' => true] becomes {"name": "Alice", "age": 28, "active": true} in JSON. While this seems straightforward, the conversion involves rules PHP developers must keep in mind: PHP single-quoted strings become double-quoted JSON strings; PHP true, false, and null map directly to their JSON equivalents; and integer-keyed PHP arrays convert to JSON arrays while string-keyed ones become JSON objects.
The converter processes PHP array syntax server-side in a tightly controlled environment. Before any evaluation occurs, the input passes through a security filter that scans for dangerous PHP tokens — file system functions, network calls, process execution, encoding tricks, and more are all blocked at the token level. The input is stripped of any leading <?php or variable assignment to isolate just the array expression.
Once evaluated, the resulting PHP data structure is passed to json_encode() with Unicode-safe flags, producing valid JSON. You can choose between pretty-printed output with indentation or minified single-line output.
The converter handles all standard PHP array forms. Indexed arrays like [1, 2, 3] become JSON arrays [1, 2, 3]. Associative arrays like ['key' => 'value'] become JSON objects {"key": "value"}. Mixed arrays with both string and integer keys, non-sequential integer keys, and deeply nested multi-dimensional structures are all supported. Both modern short syntax [] and the classic array() notation work interchangeably.
The Pretty Print option adds two-space indentation and line breaks, producing JSON that is easy to read, diff in version control, and share with colleagues. Use this during development and debugging. The Minified option strips all whitespace and produces a compact single-line JSON string, the format used in HTTP response bodies and anywhere bytes matter. Minified JSON is typically 10–30% smaller than its pretty-printed equivalent depending on nesting depth.
Paste only the array expression. You can include a leading $variable = or <?php — the tool strips these automatically. Avoid PHP expressions that depend on runtime values like function calls such as date() or env() since these cannot be safely evaluated. Stick to literal values: strings, integers, floats, booleans, and null for reliable results.
When dealing with Unicode characters in string values, the output uses JSON_UNESCAPED_UNICODE to preserve readable characters rather than escaping them to \uXXXX sequences. This keeps the JSON human-readable while remaining fully compliant with the JSON specification.