JSON to PHP Array Converter — Free Online Tool
Convert JSON to PHP associative array syntax with proper types and nested structure using AI. Free, no sign-up.
JSON to PHP Array Converter — Free Online Tool
About JSON to PHP Array Converter — Free Online Tool
The JSON to PHP Array converter transforms JSON objects and arrays into native PHP associative array syntax, producing ready-to-paste PHP code using array() or short [] notation. Developers use it to bootstrap configuration files, seed test fixtures, or integrate API responses into PHP codebases without writing repetitive array syntax by hand.
JSON to PHP Type Mapping
| JSON Type | JSON Example | PHP Output | PHP Type |
|---|---|---|---|
| Object | {"key": "value"} | ['key' => 'value'] | Associative array |
| Array | [1, 2, 3] | [1, 2, 3] | Indexed array |
| String | "hello" | 'hello' | string |
| Number (integer) | 42 | 42 | int |
| Number (float) | 3.14 | 3.14 | float |
| Boolean true | true | true | bool |
| Boolean false | false | false | bool |
| Null | null | null | null |
| Nested object | {"a": {"b": 1}} | ['a' => ['b' => 1]] | Nested associative array |
| Array of objects | [{"id":1}] | [['id' => 1]] | Indexed array of associative arrays |
PHP Array Syntax Comparison
| Syntax Style | Example | PHP Version | Notes |
|---|---|---|---|
| Short array syntax | $a = ['key' => 'val']; | 5.4+ | Preferred in modern PHP; cleaner and concise |
| Long array syntax | $a = array('key' => 'val'); | All versions | Backward-compatible; required before PHP 5.4 |
| json_decode to stdClass | json_decode($json) | 5.2+ | Returns object, not array; no static PHP code |
| json_decode to array | json_decode($json, true) | 5.2+ | Runtime conversion; requires JSON string at runtime |
| Static PHP array | $a = ['key' => 'val']; | 5.4+ | Best for config files, fixtures, and hardcoded data |
Frequently Asked Questions
How do I convert JSON to a PHP associative array?
You can convert JSON to a PHP associative array at runtime using json_decode($jsonString, true), where the second argument true forces an associative array instead of an stdClass object. For static data you want embedded directly in PHP source code — such as config files or test fixtures — use an online converter like this tool to generate the array literal syntax without writing it by hand.
What is the difference between json_decode and a static PHP array?
json_decode parses a JSON string at runtime, so your PHP file must include the raw JSON string and decode it on every execution. A static PHP array literal like ['key' => 'value'] is parsed at compile time, has no runtime overhead, and is easier for IDEs and static analyzers to inspect. Use static arrays for data that does not change; use json_decode when consuming external or dynamic JSON payloads.
Does PHP use arrow syntax or fat arrow for associative arrays?
PHP uses the fat arrow => operator (not ->) to separate keys from values in associative arrays — for example, ['name' => 'Alice', 'age' => 30]. The -> operator is reserved for accessing object properties. This is a common source of confusion when coming from JavaScript, where objects use : for key-value pairs.
How are nested JSON objects converted to PHP?
Each nested JSON object becomes a nested PHP associative array. For example, {"address": {"city": "London"}} converts to ['address' => ['city' => 'London']]. There is no depth limit in PHP array literals, so deeply nested structures are fully supported. The converter handles arbitrary nesting automatically.
Should I use array() or [] syntax in PHP?
The short [] syntax is recommended for all new PHP code targeting PHP 5.4 and above, which covers virtually every production environment in use today. It is less verbose and more consistent with array literals in other languages. Use the long array() syntax only if you must support PHP 5.3 or earlier, which reached end-of-life in 2014.
If jsondecode.com saved you time, share it with your team
Free forever. No ads. No sign-up. Help other developers find it.