How to use the json to php array converter
- Paste your JSON text into the JSON input field.
- Choose your preferred indentation: 2 spaces, 4 spaces or tab.
- The PHP array output updates automatically as you type.
- Copy the generated PHP code and paste it into your project.
How the conversion works
The converter parses the JSON string into native JavaScript values, then walks the resulting structure recursively to emit PHP short array syntax. JSON objects become associative arrays using the [key => value] form, while JSON arrays become indexed arrays. Strings are wrapped in single quotes with internal single quotes escaped as \'. Booleans map directly to PHP true and false, and JSON null becomes PHP null.
For example, the JSON input {"user": "alice", "active": true} produces the following PHP code:
[
'user' => 'alice',
'active' => true,
]
This recursive approach means that no matter how deeply nested your original data is, every level translates cleanly into matching PHP syntax without losing structural information.
Type mapping reference
Every JSON data type has a direct equivalent in PHP. The table below shows how each type is translated during the json to php array conversion.
| JSON type | PHP output | Example |
|---|---|---|
| Object | Associative array | {"a":1} becomes ['a' => 1] |
| Array | Indexed array | [1,2] becomes [1, 2] |
| String | Single-quoted string | "hi" becomes 'hi' |
| Number | Integer or float | 42 stays 42, 3.14 stays 3.14 |
| Boolean | true / false | true becomes true |
| Null | null | null becomes null |
Understanding these mappings helps you predict exactly what the output will look like before you even run the conversion, which is especially useful when debugging configuration files or API responses.
Handling special characters in strings
When converting JSON strings to PHP, the tool uses single quotes because they prevent accidental variable interpolation in PHP. Any single quote inside the original JSON string is escaped with a backslash. A string that contains a control character such as a newline, tab or NUL is written in double quotes with PHP escapes (
, ,