About Array to JSON Converter
This tool turns an array written in PHP or JavaScript syntax into JSON. It reads PHP short arrays, the older array() form, "key" => value pairs, single and double quoted strings, numbers, true, false and null, then prints indented JSON you can paste into an API request, a config file or a test fixture.
Converting by hand is slow because PHP uses => where JSON uses a colon, and PHP code often uses single quotes that JSON does not allow. The converter handles those differences for you and parses the text with a small tokenizer instead of running it.
How to use Array to JSON Converter
- Paste a PHP array, or a JavaScript array or object literal, into the input box.
- Click Run Tool. If the syntax is invalid, the message shows the character position where parsing stopped.
- Copy the formatted JSON or download it as a text file.
Example
Input
['name' => 'NHP Learning', 'topics' => ['PHP', 'JSON'], 'free' => true, 'price' => 0]
Output
{
"name": "NHP Learning",
"topics": [
"PHP",
"JSON"
],
"free": true,
"price": 0
}Common uses
- Preparing a PHP array from WordPress or Laravel code as a JSON payload for an API request.
- Turning a JavaScript object literal into strict JSON for a .json configuration file.
- Building test fixtures from data structures that already exist in your PHP code.
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 run my PHP code?
No. The text is parsed in your browser by a tokenizer, so functions, variables and expressions are not evaluated. Only literal arrays, strings, numbers, booleans and null are supported.
Why does it differ from PHP json_encode()?
json_encode() writes compact JSON by default and escapes slashes and non-ASCII characters unless flags such as JSON_UNESCAPED_SLASHES are set. This tool prints indented JSON with the real characters, which is easier to read.
Are indexed and associative arrays treated differently?
Yes, as in PHP. A list without keys becomes a JSON array, while an array with "key" => value pairs becomes a JSON object.