JSON to PHP Array Converter
NOVOConvert JSON to PHP array code with short or long syntax, or read a PHP array literal back to JSON, all in your browser.
Funciona 100% no seu navegador — o que você insere nunca é enviado nem armazenado nos nossos servidores.
Esta ferramenta ainda não está totalmente traduzida, por isso parte do texto continua em inglês. A ferramenta funciona da mesma forma em todos os idiomas.
JSON → PHP: objects become associative arrays, strings are single-quoted with only \ and ' escaped, and numbers keep their exact digits (98.60 stays 98.60). The var_export() style always writes keys and ignores the indent and syntax options.
PHP → JSON: reads literal arrays only: [ ] or array( ), single- and double-quoted strings without variables, numbers (hex, octal, binary and 1_000 included), true, false, null and =>. Constants, function calls, concatenation and heredoc strings are reported as unsupported, with their line and column.
Exemplos rápidos
Entradas típicas e os resultados que esta ferramenta gera.
Visão geral
The JSON to PHP array converter writes PHP source code from JSON, so a config file, fixture or API response can be pasted straight into a PHP project. Objects become associative arrays, JSON lists become indexed arrays, and null, true and false keep their meaning.
You can choose short [ ] or long array( ) syntax, indent with 2 spaces, 4 spaces or a tab, wrap the array in <?php return …; or produce var_export-style output. Strings are single-quoted with only the backslash and the single quote escaped, and numbers keep their exact digits.
The reverse direction reads a literal PHP array and returns JSON. Constants, function calls and variables are reported as unsupported with a line and column. Nothing leaves your browser.
Por que usar esta ferramenta?
- Paste JSON data straight into PHP config files
- Short, long or var_export-style output
- Exact number digits and correct string escaping
- Reverse direction for simple PHP arrays
- Runs in your browser, free, no sign-up
Recursos
Both directions
Convert JSON to PHP source or a literal PHP array back to JSON.
Short or long syntax
Write [ ] or array( ), with 2-space, 4-space or tab indentation and optional trailing commas.
Three output styles
Plain array literal, a <?php return …; file, or var_export-style text with explicit keys.
Correct string escaping
Single quotes escape only \ and '. Strings with line breaks can use double quotes with \n and \$ escapes.
Exact numbers
Numbers are copied digit for digit, so 98.60 stays 98.60 and 1.0 stays a float.
Clear errors
Invalid JSON and unsupported PHP syntax are reported with line and column numbers.
Como usar
Choose a direction
Select JSON → PHP array or PHP array → JSON under Direction.
Paste or upload
Paste your data, use Upload file, or press Load sample.
Set the options
Pick the output style, array syntax, indent, trailing commas and string quoting.
Copy or download
Press Copy for the clipboard or Download to save a .php or .json file.