Skip to main content

PHP Array to JSON

Paste an array from a PHP config file and get JSON you can use straight away.

JSON result
Your result will appear here

This reads literal values only. If the array contains a variable, a PHP constant or a function call, it says so rather than guessing at the value.

Converted entirely in your browser — nothing is sent to a server.

About this tool

PHP array to JSON reads an array written in PHP source and converts it to usable JSON, without running PHP.

The common job is moving a config across languages — a list of constants or a mapping that lives in a PHP file and now has to work in JavaScript, Python, or as plain JSON. Retyping it line by line is slow and error-prone.

The parser handles what real files contain: array(…) and the short bracket form, => keys, nested arrays, all three comment styles, and trailing commas. It also follows PHP's single-quote rule correctly — backslashes are not interpreted — so 'C:\temp' stays a Windows path instead of becoming a tab character.

What it deliberately does not do is guess. If the array contains a variable, a PHP constant or a function call, it says it cannot read that value, because producing a plausible-looking wrong answer is worse than producing none.

How to use

  1. 1Copy the array out of your PHP config file
  2. 2Paste it in — both array() and the short bracket syntax work
  3. 3The JSON appears immediately, already formatted
  4. 4Copy or download it

Frequently asked questions

What syntax is supported?
Both array(…) and short brackets, => keys, nested arrays, strings in either quote style, numbers, true/false/null, and trailing commas.
Why can’t it handle a variable in my code?
A variable’s value only exists at runtime, and this tool does not execute PHP. It says so plainly rather than guessing — a result that looks right but is wrong is worse than no result.
Why doesn’t C:\\temp in single quotes become a tab?
Because PHP single-quoted strings do not interpret backslashes except for \\\\ and \\\x27. This tool follows the same rule, so Windows paths survive intact.
Can I paste code with comments in it?
Yes — //, # and /* */ are all skipped, so you can paste a whole config file section as-is.
How is this different from running json_encode?
The result is the same for ordinary data, but you do not need PHP installed. Useful when all you have is the source file, or you are on a machine without PHP.

Related tools

PHP Array to Object

Turn a PHP array literal into a JavaScript object.

PHP Serialize Converter

Read a PHP serialize() blob and convert it to and from JSON.

JSON Formatter

Format, validate and minify JSON — for developers.

JSON ↔ YAML Converter

Convert between JSON and YAML in one click.