JSON to PHP Array Converter
PHP array
Click the output to copy it to your clipboard.
About this tool
This tool converts JSON into a PHP array definition. Paste your JSON, press Convert, and copy the result into your code. It is handy for turning an API response or a config file into a fixture, a test case, or a hard-coded default.
Everything runs in your browser. The JSON you paste is never sent to a server.
Example
Input:
{"name":"cat","tags":["a","b"],"active":true,"memo":null,"count":3}
Output:
array(
'name' => 'cat',
'tags' => array(
'a',
'b'
),
'active' => true,
'memo' => null,
'count' => 3
)
Things to know
- The output uses the long
array()syntax. If you prefer the short[]syntax, replace it in your editor after copying. - Strings are written with single quotes, and
'and\are escaped for you. - Numbers are parsed as JavaScript numbers, so integers above 253 (about 9 quadrillion) lose precision. Keep large IDs as strings in your JSON.
- Object keys always become quoted string keys. PHP turns numeric strings such as
'1'into integer keys, which is normally what you want.
FAQ
Q. I get an "Invalid JSON" error.
A. JSON does not allow trailing commas, single-quoted strings, or comments. Remove them and try again. The error message includes the position the parser stopped at.
Q. Is my data uploaded anywhere?
A. No. The conversion runs entirely in your browser, and this page does not send what you type to any server.
Q. Can I convert CSV or a plain list instead?
A. Yes. Use CSV/TSV to Array Code for tables, or Text Lines to Array Code for one item per line.