PHP Array to JSON
Convert a PHP array literal into valid JSON.
Paste a PHP array literal below - this tool converts it into valid, formatted JSON.
More Programming Language Tools
View all 23Going the other direction? Use the JSON to PHP Array converter instead.
What Does This Tool Do?
It parses PHP array syntax (['key' => 'value'] or the older array('key' => 'value') form, including nested arrays) and converts it into equivalent JSON.
Why Use This Tool?
Useful when you have PHP configuration or test data and need the equivalent JSON - for an API response mock, a JavaScript test fixture, or documentation.
How to Use It
- Paste a PHP array literal.
- Click Convert.
- Copy the resulting JSON.
Limitations
This handles array literals containing plain values (strings, numbers, booleans, null, nested arrays) - PHP-specific constructs like object instances, constants, or function calls within the array aren't representable in JSON and won't convert.
Example
array(
'site' => 'Byteary',
'free' => true,
'limits' => ['requests' => 60, 'window' => '1m'],
'tags' => ['tools', 'developers'],
)
becomes:
{
"site": "Byteary",
"free": true,
"limits": {
"requests": 60,
"window": "1m"
},
"tags": [
"tools",
"developers"
]
}
Lists vs Objects
PHP uses one array type for both lists and key-value maps; JSON has two. An array with keys 0, 1, 2... in order becomes a JSON array; any other keys produce a JSON object. This is the same rule PHP's json_encode() follows.
Where It Helps
- Building mock API responses from Laravel config or test data.
- Sharing PHP settings with a JavaScript front end.
- Documenting a configuration format in JSON.
In Your Own Code
echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
Those flags give readable output, keep / unescaped in URLs, and keep non-English text as-is.
Convert back with JSON to PHP Array, and format the JSON with the JSON Formatter.
Frequently Asked Questions
Explore More Tools
Keep going with related categories and our most used tools.