Go to Sign up
Note: Your files never leave your device. We don't upload, transfer, or store your data.
A PHP array is an ordered map that associates keys with values. Unlike JSON, which has separate object and array types, PHP uses a single array construct for both indexed lists and associative maps.
// Indexed array
['Apple', 'Banana', 'Cherry']
// Associative array
['name' => 'Alice', 'email' => '[email protected]']
PHP arrays support nesting, mixed key types, and heterogeneous values — making them the primary data structure in PHP applications.
// Legacy syntax (PHP 4+)
array('key' => 'value', 'name' => 'Alice')
// Short syntax (PHP 5.4+) — recommended
['key' => 'value', 'name' => 'Alice']
This tool outputs short array syntax ([]), which is the modern standard.
JSON (JavaScript Object Notation) is a lightweight, human-readable text format defined by RFC 8259. It uses key-value pairs and ordered lists to represent structured data.
{"name": "Alice", "age": 30, "active": true}| Feature | JSON | PHP Array |
|---|---|---|
| Object type | Separate object {} and array [] | Single array type with string/int keys |
| Key quoting | Always double quotes | Single quotes convention ('key' => ...) |
| Key-value separator | Colon : | Arrow => |
| Boolean values | true / false (lowercase) | true / false (lowercase, same) |
| Null | null | null |
| Trailing comma | Not allowed | Allowed |
| String quoting | Double quotes only | Single or double quotes |
| Comments | Not supported | N/A (PHP supports // and /* */) |
| JSON Type | JSON Example | PHP Output |
|---|---|---|
| String | "hello" | 'hello' |
| Integer | 42 | 42 |
| Float | 3.14 | 3.14 |
| Boolean true | true | true |
| Boolean false | false | false |
| Null | null | null |
| Object | {"a": 1} | ['a' => 1] |
| Array (of values) | [1, 2, 3] | [1, 2, 3] |
| Array (of objects) | [{"a": 1}] | [['a' => 1]] |
| Use Case | Description |
|---|---|
| Configuration files | Embed JSON API responses as PHP config arrays |
| Database seeding | Convert JSON fixture data into PHP seeder files for Laravel, Symfony, or CodeIgniter |
| Migration | Port JSON-based configs to PHP-based frameworks (WordPress, Drupal, Magento) |
| Caching | Store pre-parsed PHP arrays in OPcache for faster access than json_decode() at runtime |
| Code generation | Generate PHP model or fixture files from JSON schemas |
| Testing | Create PHP test data from JSON samples for PHPUnit tests |
| Hardcoding data | Embed static data directly in PHP source instead of reading JSON files |
PHP has a built-in json_decode() function. Understanding when to use each approach matters.
<?php
$json = '{"name": "Alice", "age": 30}';
$data = json_decode($json, true);
// $data = ['name' => 'Alice', 'age' => 30]
| Aspect | json_decode() |
|---|---|
| When to use | Dynamic JSON from APIs, files, user input |
| Performance | Parses at runtime — slower for static data |
| Flexibility | Handles any JSON at runtime |
| Error handling | Returns null on invalid JSON; use json_last_error() |
<?php
// Hardcoded PHP array — no runtime parsing needed
$data = [
'name' => 'Alice',
'age' => 30,
'active' => true,
'roles' => ['admin', 'editor'],
'address' => [
'city' => 'New York',
'zip' => '10001',
],
];
| Aspect | This Tool (Code Generation) |
|---|---|
| When to use | Static data, config files, seeders, test fixtures |
| Performance | Zero parsing overhead — OPcache-optimized |
| Flexibility | Output is editable PHP code |
| Use case | Laravel seeders, WordPress configs, PHPUnit data providers |
All processing runs entirely in your browser. No data is uploaded to any server. Your JSON data never leaves your device.
Choose one of two input methods:
Upload a file: Click "Choose File" and select a .json file, or drag it into the upload area.
Paste data: Click "Enter Data" to switch to the code editor. Paste your JSON. A "Valid JSON" badge confirms correct formatting.
Click Convert. The PHP array appears in the "Output Data" panel.
Click Copy to Clipboard to paste into your .php file.
Premium users can click Download File to save.
Input JSON:
{
"id": 1,
"name": "Alice",
"email": "[email protected]",
"active": true,
"roles": ["admin", "editor"],
"address": {
"city": "New York",
"zip": "10001"
}
}
Output PHP Array:
[
'id' => 1,
'name' => 'Alice',
'email' => '[email protected]',
'active' => true,
'roles' => ['admin','editor',],
'address' => [
'city' => 'New York',
'zip' => '10001',
],
]
Input JSON:
[
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"},
{"id": 3, "name": "Charlie"}
]
Output PHP Array:
[
['id' => 1,'name' => 'Alice',],
['id' => 2,'name' => 'Bob',],
['id' => 3,'name' => 'Charlie',],
]
Input JSON:
{
"product": "Laptop",
"price": 999.99,
"inStock": true,
"tags": ["electronics", "computers"],
"specs": {
"cpu": "M2",
"ram": 16,
"storage": null
}
}
Output PHP Array:
[
'product' => 'Laptop',
'price' => 999.99,
'inStock' => true,
'tags' => ['electronics','computers',],
'specs' => [
'cpu' => 'M2',
'ram' => 16,
'storage' => null,
],
]
<?php
// database/seeders/UserSeeder.php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class UserSeeder extends Seeder
{
public function run(): void
{
$users = [
['id' => 1,'name' => 'Alice','email' => '[email protected]','active' => true,],
['id' => 2,'name' => 'Bob','email' => '[email protected]','active' => false,],
];
\DB::table('users')->insert($users);
}
}
<?php
// tests/Feature/UserTest.php
use PHPUnit\Framework\TestCase;
class UserTest extends TestCase
{
public static function userInfoProvider(): array
{
return [
['id' => 1,'name' => 'Alice','email' => '[email protected]','active' => true,],
];
}
#[DataProvider('userInfoProvider')]
public function testUserIsActive(array $user): void{
$this->assertTrue($user['active']);
}
}
<?php
// wp-content/themes/mytheme/config.php
$theme_config = [
'site_name' => 'My Blog',
'posts_per_page' => 10,
'sidebar' => true,
'social_links' => [
'twitter' => 'https://twitter.com/example',
'github' => 'https://github.com/example',
],
];
No. All conversion happens locally in your browser using JavaScript. Your data never leaves your device.
The tool outputs short array syntax ([]) using single-quoted string keys ('key' => value). This is the modern PHP 5.4+ standard.
All standard JSON types: strings, integers, floats, booleans, null, objects (converted to associative arrays), and arrays (converted to indexed arrays). Nested structures are handled recursively.
Yes. The output is valid PHP array syntax that works directly in Laravel database seeders, factory definitions, and PHPUnit data providers.
json_decode() parses JSON at runtime. This tool generates static PHP array code you can paste directly into .php files. Use json_decode() for dynamic data (APIs, files); use this tool for static data (seeders, configs, test fixtures).
No. The tool outputs short syntax ([]) only, which is the recommended format since PHP 5.4.
The tool processes data entirely in your browser. Files up to 10 MB typically convert without issues on modern hardware.
Yes. The tool is responsive and works on smartphones and tablets.
The tool displays an "Invalid JSON" badge when the input is malformed. Fix the JSON and try again.