JSON to PHP Array Converter
FV-18Paste JSON and press Convert to get a PHP array literal you can paste into code or a config file. Numbers, booleans and null keep their type. It runs in your browser.
Runs in your browser. Nothing is uploaded.
JSON
PHP
How to use it
- Paste JSON into the input box, or open a .json file.
- Choose short [ ] or long array( ) syntax and how to wrap the result.
- Press Convert, then copy the PHP into your file.
- Use the Return wrapper for a config file that your code loads with require.
What the output looks like
JSON objects become arrays with quoted string keys written as 'key' => value, and JSON arrays become plain lists. The result can be written as $data = [...];, as <?php return [...]; for a config file, or as the expression alone. Indentation is yours to pick. This is different from var_export, which writes array( ) and prints a numeric key for every list item.
Types and strings
Integers, floats, true, false and null are written as PHP literals, and floats are copied as written. Strings go in single quotes, with only the backslash and the apostrophe escaped. A string that holds a control character, such as a line break, uses double quotes with escape sequences, and dollar signs are escaped there so PHP does not read them as variables.
Edge cases
An integer beyond the PHP integer range, 9223372036854775807, is written as a quoted string with a comment, because PHP would turn it into a float and drop digits. An empty object and an empty array both become [], since PHP has one array type. A key that looks like a whole number, such as "123", becomes an integer key when PHP builds the array.
Questions people ask
How do I convert JSON to a PHP array?
Paste the JSON and press Convert. Copy the PHP literal into your file. To do the same at run time in PHP, call json_decode($json, true), which returns an associative array without needing the literal.
What is the difference between short and long syntax?
Short syntax writes [ ] and long syntax writes array( ). They produce the same array. The short form is the one most code uses today, so it is the default.
Why is my big integer in quotes?
Integers above 9223372036854775807 do not fit a PHP int, and PHP would turn them into floats and lose digits. The tool keeps every digit by writing them as strings and adds a comment so you can see which ones.
Why do an empty object and an empty list look the same?
PHP has a single array type, so {} and [] are both []. If you need to tell them apart, handle that in your code, or keep the data as JSON and use json_decode with objects.
Can I use the Return option for a config file?
Yes. It writes <?php followed by return [...]; so a file such as config.php can be loaded with $config = require 'config.php';. The other two wrappers write only the assignment or only the expression.
Does it handle emoji and other Unicode text?
Yes. Text is written as UTF-8, so emoji and accented letters stay readable in the PHP file. A lone surrogate, half of an emoji pair, cannot be UTF-8, so the tool reports an error instead.
About this tool
Objects become arrays with string keys and JSON arrays become lists, written as a PHP literal you can paste into code. Integers, floats, booleans and null keep their type; floats are copied as written. An integer beyond the PHP integer range (9223372036854775807) is written as a quoted string with a comment, because PHP would turn it into a float and drop digits. Strings go in single quotes with only the backslash and apostrophe escaped; a string with a control character such as a line break uses double quotes and escape sequences instead. An empty object and an empty array both become [], since PHP has one array type. Keys keep their order, and a repeated key is written twice, so the later one wins in PHP. Keys that look like whole numbers, such as "123", become integer keys when PHP builds the array. A lone surrogate in a string raises an error because it cannot be UTF-8.