JSON To PHP Array Converter Online - JS Object To PHP
Convert JSON or JavaScript object code into a clean, ready-to-use PHP associative array instantly. This online tool supports nested structures, short and long PHP syntax, key transformations (snake_case, camelCase, PascalCase, kebab-case), dot notation flattening, smart number handling, and large array formatting. All processing runs securely in your browser with no data uploaded.
Simply paste your JSON in the input box and get properly formatted PHP code with correct syntax, nested structures, and escaped strings.
Features
- Convert JSON to PHP associative array instantly
- Accepts standard JSON format
- Accepts JavaScript object notation (unquoted keys)
- Support for nested objects and multi-level arrays
- Choose short
[ ]or longarray()syntax - Single or double quote output
- Smart number handling options
- Alphabetical key sorting
- Dot Notation Flattening - convert nested objects into single-level keys
- Format large arrays with custom split and group size
- Key Transformations: convert object keys to (snake_case, camelCase, PascalCase, kebab-case)
- Proper string escaping
- Works fully in browser - no data uploaded
- One click copy and download
Example
JSON Input
{
"name": "Ali",
"age": 28,
"active": true,
"skills": ["PHP", "JS"]
} PHP Output (Short Syntax)
$data = [
'name' => 'Ali',
'age' => 28,
'active' => true,
'skills' => [
'PHP',
'JS'
]
]; Paste your JSON code below to instantly convert it into a valid PHP array. Supports nested structures, booleans, null values, and both short [ ] and long array() syntax.
This tool accepts both JSON and JavaScript object style code.
Note: If you paste JavaScript object-style code (without quoted keys), the editor may display JSON error warnings. You can safely ignore those and click "Convert to PHP Array" the tool will automatically normalize the input and generate the correct result.
Double quotes → "key"=> "value"
Single quotes -> 'key'=> 'value'
Keep as numbers>
age => 25 Convert to strings>
age => "25" Detect numeric strings -> "25"> 25
Useful for Laravel configs, validation rules, and translation files. Example:
{ "user": { "id": 1 } } to ['user.id' => 1].When an array has many items (100+), format output in blocks of 10 items per line to avoid extremely long lines.
Short syntax -> [ ]
Long syntax -> array()
🔄 Convert JSON → PHP Array Instantly
{"name":"Ali","age":30} ['name' => 'John', 'age' => 30] ⇄ Accepts JSON & JavaScript Object Syntax
{ id: 5, title: "Test" } Unquoted keys are automatically normalized.
🪜 Nested Object Support
{"user":{"profile":{"city":"Dubai"}}} Converted to proper multi-level PHP structure.
🔁 Short or Long Syntax
[ 'a' => 1 ]
array('a' => 1) • Dot Notation Flattening
{"user":{"id":1}} ['user.id' => 1] 🔡 Key Transformations
- snake_case → user_name
- camelCase → userName
- PascalCase → UserName
- kebab-case → user-name
☰ Large Array Formatting
Split when > 100 items, group 10 items per line.
Default:
$data = ['A', 'B', 'C', '…']; Grouping Lines (Large Arrays):
$data = [
'A', 'B', 'C',
'D', 'E', 'F',
'G', 'H', 'I',
'…'
];
🔢 Smart Number & String Handling
Control numeric conversion and safe escaping.
No change (default):
$data = [
'id' => 123,
'age' => 30,
'phone' => '12345'
]; Convert numbers to strings:
$data = [
'id' => '2',
'age' => '30',
'phone' => '12345'
]; Convert numeric strings to numbers:
$data = [
'id' => 123,
'age' => 30,
'phone' => 12345
]; 🔠 Alphabetical Key Sorting
Automatically sort object keys from A→Z for cleaner, consistent, and more readable PHP array output.
Default:
$data = [
'e' => '4',
'b' => '2',
'a' => '1',
'c' => '3'
]; Alphabetical order object keys:
$data = [
'a' => '1',
'b' => '2',
'c' => '3',
'e' => '4'
]; 🔒 Browser Based & Private
All processing happens locally - no data uploaded.
🖱️ One-Click Actions
Copy output or download as .php file.
Is this conversion done on the server?
No. All processing happens in your browser using JavaScript. Your JSON data is never sent to any server.
Does the tool accept non-quoted object keys?
Yes. You can paste JavaScript object code or valid JSON. The tool automatically normalizes both formats before generating the PHP array.
Which PHP syntax is better - short or long?
Short syntax [ ] is recommended for modern PHP (5.4+). Long syntax array() is provided for legacy projects.
Can it handle nested JSON?
Yes. Objects and arrays of any depth are converted into proper PHP structures.
What are Key Transformations?
This option lets you automatically rename all object keys into a consistent style such as snake_case, camelCase, PascalCase, or kebab-case before generating the PHP array.
Which format should I use?
- camelCase - common for JavaScript projects
- snake_case - recommended for PHP and databases
- PascalCase - useful for class-style keys
- kebab-case - suitable for URLs and HTML attributes
Does it affect values?
No. Only object keys are transformed. All values remain unchanged.
Does it work with nested JSON?
Yes. The transformation is applied recursively to all nested objects and arrays.
What is Dot Notation Flattening?
It converts nested JSON objects into a single-level PHP array using dot-separated keys, making deeply nested values easier to access.
When should I use it?
Use this option when working with Laravel validation rules, configuration arrays, form processing, or when you need flat key/value structures instead of nested arrays.
Does it modify the data values?
No. Only the structure of the keys changes. All original values remain exactly the same.
Is this option required?
No. It is optional and disabled by default. Enable it only when you need a flat array format.
How are numbers handled?
You can keep numbers as numeric values, convert them to strings, or detect numeric strings automatically.
What is "Chunk Large Arrays"?
For very large arrays, the tool can split output into groups (e.g., 10 items per line) to keep code readable.
Does it support special characters?
Yes. Strings are safely escaped to produce valid PHP output.
Can I convert JSON from a URL?
Yes. Use the JSON URL field to fetch remote JSON before converting.
Is there a size limit?
Conversion runs in your browser memory. Very large JSON may depend on your device performance.