Paste a PHP array literal and get valid JSON — associative, indexed, and nested arrays, converted instantly in your browser.
PHP has a single array type that covers both lists and dictionaries, so this tool follows the same rule PHP's own json_encode() uses: if an array's keys are the sequential integers 0, 1, 2, … in order, it converts to a JSON array; otherwise — any string key, non-sequential integer key, or explicit => assignment — it converts to a JSON object. Both the long array(...) syntax and the short [...] syntax are supported, and arrays can be nested to any depth.
| Term | Meaning |
|---|---|
| Indexed array | An array with sequential integer keys starting at 0 — converts to a JSON array [...] |
| Associative array | An array with string keys, or integer keys that skip or start elsewhere — converts to a JSON object {...} |
| Nested array | An array used as a value inside another array — converted recursively, preserving structure |
| Pretty-print / Minify | Whether the JSON output is indented for readability or written as compact single-line JSON |
The PHP Array to JSON Converter is an online developer tool that transforms PHP array syntax into valid JSON. Whether you're working with associative arrays, indexed arrays, multidimensional arrays, or nested data structures, this converter automatically parses your PHP array and generates standards-compliant JSON that can be used in APIs, JavaScript applications, databases, configuration files, and third-party integrations.
PHP arrays are one of the most commonly used data structures in web development. However, many frontend frameworks, REST APIs, mobile applications, and cloud services expect data in JSON format. Instead of manually rewriting array structures, this converter performs the conversion instantly while preserving nested objects, arrays, numbers, booleans, strings, and null values.
Everything runs directly inside your browser, so your source code remains private. Simply paste your PHP array, choose whether to generate pretty-printed or minified JSON, and copy or download the result.
JSON has become the standard format for exchanging structured data across different programming languages and platforms. Converting PHP arrays into JSON makes your data portable, readable, and compatible with modern applications.
.json file.Suppose you have the following PHP array:
$user = array(
"name" => "John Doe",
"age" => 32,
"active" => true,
"roles" => array("Admin", "Editor")
);
The converter generates the following JSON:
{
"name": "John Doe",
"age": 32,
"active": true,
"roles": [
"Admin",
"Editor"
]
}
This JSON can now be used directly in REST APIs, JavaScript applications, AJAX responses, mobile apps, and cloud services without any additional formatting.
If your converter reports a parsing error, first validate the PHP array syntax. Most issues are caused by a small syntax mistake such as a missing comma or bracket.
A PHP Array to JSON Converter is an essential utility for PHP developers, API engineers, backend programmers, and anyone working with structured data. Instead of manually rewriting arrays into JSON format, you can instantly generate clean, standards-compliant JSON while preserving nested objects, arrays, and data types.
Whether you're building REST APIs, creating configuration files, debugging applications, or integrating third-party services, this tool simplifies the conversion process, reduces manual errors, and improves productivity. Since the conversion happens directly in your browser, it's also a fast and privacy-friendly solution for everyday development tasks.
null values while preserving the overall data structure.array() syntax and the short [] syntax are supported.