Skip to content
JSON Runs offline

JSON to PHP Array

Convert JSON into a paste-ready PHP array literal, with short or long syntax and a variable or define() wrapper.

Array syntax

Input

0 chars

Output

0 chars
Ctrl

Questions

Does the output include a <?php opening tag?

No. This produces a single PHP statement (an assignment or a define() call) meant to be pasted into existing PHP code, not a standalone file - add your own opening tag if you save it as its own .php file.

Will `1.0` in my JSON come back out as `1.0` in the PHP?

No, and this is a JavaScript limitation, not a choice: JSON.parse collapses 1.0 and 1 to the identical JS number 1 before this tool ever sees it, so both render as the PHP int 1. If you need a literal float, write a fractional value like 1.5, or add a decimal place PHP will keep, e.g. 1.1.

What happens with very large integers, like ones bigger than 2^53?

They lose precision. JSON numbers are parsed with JSON.parse into ordinary JavaScript doubles, which cannot represent every integer exactly past Number.MAX_SAFE_INTEGER (9,007,199,254,740,991) - this is the same limitation every JSON tool in this toolbox that uses JSON.parse has. Keep huge IDs as JSON strings if you need them exact.

I chose Constant wrap with the default name "array" and now I can't reference the constant by its bare name - is that a bug?

No - it is PHP's own reserved-word rule. The tool uppercases your name to build the constant, so the default "array" becomes the constant ARRAY, and `array` is a reserved keyword in PHP regardless of case, so a bare ARRAY token elsewhere in your code will not resolve to it. define('ARRAY', ...) itself is perfectly valid and the constant is set; fetch it with constant('ARRAY') instead of the bare word, or pick a different variable name before switching to Constant wrap.

Open JSON to TypeScript

JSON to TypeScript

Turn one JSON example into readable, multi-interface TypeScript types.

JSON
Open JSON Formatter

JSON Formatter

Format, indent and inspect JSON with clear error reporting.

JSON
Open JSON Validator

JSON Validator

Check whether JSON is valid and see exactly where it breaks.

JSON