About PHP Array to JSON Converter
Paste a PHP array and get valid JSON back. The tool understands both the short [] syntax and the classic array() form, key => value pairs, nested arrays, single and double quoted strings, numbers, booleans and null.
Associative arrays become JSON objects and plain lists become JSON arrays, matching how PHP json_encode() treats them. Because the conversion runs in the browser and nothing is executed, it is safe to paste code from a project without exposing it.
How to use PHP Array to JSON Converter
- Copy a PHP array literal from your code and paste it into the input box.
- Click Run Tool to convert it.
- Copy the JSON, or fix the reported syntax error and run it again.
Example
Input
array('id' => 7, 'title' => 'Hello World', 'tags' => array('php', 'json'), 'published' => true)Output
{
"id": 7,
"title": "Hello World",
"tags": [
"php",
"json"
],
"published": true
}Common uses
- Creating a JSON body for an API request from an array you already built in PHP.
- Checking what json_encode() will produce for a configuration array.
- Moving data between a PHP project and a JavaScript front end.
Privacy and safety
This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.
Frequently asked questions
Does it support variables like $name inside the array?
No. Only literal values are parsed. Replace variables with sample values before converting.
What about objects and classes?
Class instances, closures and function calls are not supported. Convert them to plain arrays first.
What if I mix keyed and unkeyed items?
The result is a JSON object. Items without a key receive numeric keys starting at 0.