JSON To PHP Array

Login

Email
Password

Don't have an account yet?

Go to Sign up

Input Data
Sample {{ showCoderInput ? 'Choose File' : 'Enter Data' }}

                                
Valid JSON Invalid JSON — Cannot convert to PHP Array
Output Data
{{ copied ? 'Copied!' : 'Copy to Clipboard' }} Download File
Properties
Convert JSON to PHP online — paste, edit, and download PHP.

Convert Restart

JSON to PHP Array — Free Online JSON to PHP Converter

What Is a PHP Array?

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.

PHP Array Syntax: Legacy vs. Short

// 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.

What Is JSON?

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}

JSON vs. PHP Array — Key Differences

FeatureJSONPHP Array
Object typeSeparate object {} and array []Single array type with string/int keys
Key quotingAlways double quotesSingle quotes convention ('key' => ...)
Key-value separatorColon :Arrow =>
Boolean valuestrue / false (lowercase)true / false (lowercase, same)
Nullnullnull
Trailing commaNot allowedAllowed
String quotingDouble quotes onlySingle or double quotes
CommentsNot supportedN/A (PHP supports // and /* */)

JSON-to-PHP Type Mapping

JSON TypeJSON ExamplePHP Output
String"hello"'hello'
Integer4242
Float3.143.14
Boolean truetruetrue
Boolean falsefalsefalse
Nullnullnull
Object{"a": 1}['a' => 1]
Array (of values)[1, 2, 3][1, 2, 3]
Array (of objects)[{"a": 1}][['a' => 1]]

Why Convert JSON to PHP Array?

Use CaseDescription
Configuration filesEmbed JSON API responses as PHP config arrays
Database seedingConvert JSON fixture data into PHP seeder files for Laravel, Symfony, or CodeIgniter
MigrationPort JSON-based configs to PHP-based frameworks (WordPress, Drupal, Magento)
CachingStore pre-parsed PHP arrays in OPcache for faster access than json_decode() at runtime
Code generationGenerate PHP model or fixture files from JSON schemas
TestingCreate PHP test data from JSON samples for PHPUnit tests
Hardcoding dataEmbed static data directly in PHP source instead of reading JSON files

json_decode() vs. This Tool

PHP has a built-in json_decode() function. Understanding when to use each approach matters.

Using json_decode() (Runtime)

<?php
$json = '{"name": "Alice", "age": 30}';
$data = json_decode($json, true);
// $data = ['name' => 'Alice', 'age' => 30]

Aspectjson_decode()
When to useDynamic JSON from APIs, files, user input
PerformanceParses at runtime — slower for static data
FlexibilityHandles any JSON at runtime
Error handlingReturns null on invalid JSON; use json_last_error()

Using This Tool (Code Generation)

<?php
// Hardcoded PHP array — no runtime parsing needed
$data = [
   'name' => 'Alice',
   'age' => 30,
   'active' => true,
   'roles' => ['admin', 'editor'],
   'address' => [
       'city' => 'New York',
       'zip' => '10001',
   ],
];

AspectThis Tool (Code Generation)
When to useStatic data, config files, seeders, test fixtures
PerformanceZero parsing overhead — OPcache-optimized
FlexibilityOutput is editable PHP code
Use caseLaravel seeders, WordPress configs, PHPUnit data providers

Privacy by Design

All processing runs entirely in your browser. No data is uploaded to any server. Your JSON data never leaves your device.

How to Use This JSON to PHP Array Converter?

Step 1: Provide Your JSON Data

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.

Step 2: Convert

Click Convert. The PHP array appears in the "Output Data" panel.

Step 3: Copy or Download

  • Click Copy to Clipboard to paste into your .php file.

  • Premium users can click Download File to save.

Complete Examples

Example

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',
   ],

]

Example — Array of Records

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',],
]

Example — Nested Objects with Mixed Types

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,
   ],
]

Real-World Use Cases

Laravel Database Seeder

<?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);
   }
}

PHPUnit Data Provider

<?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']);
   }
}

WordPress Configuration

<?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',
   ],
];

Frequently Asked Questions (FAQ)

  • Does the tool upload my data?

    No. All conversion happens locally in your browser using JavaScript. Your data never leaves your device.

  • What PHP array syntax does the tool output?

    The tool outputs short array syntax ([]) using single-quoted string keys ('key' => value). This is the modern PHP 5.4+ standard.

  • What JSON types are supported?

    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.

  • Can I use this for Laravel seeders?

    Yes. The output is valid PHP array syntax that works directly in Laravel database seeders, factory definitions, and PHPUnit data providers.

  • What is the difference between json_decode() and this tool?

    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).

  • Does the tool support PHP's legacy array() syntax?

    No. The tool outputs short syntax ([]) only, which is the recommended format since PHP 5.4.

  • Is there a file size limit?

    The tool processes data entirely in your browser. Files up to 10 MB typically convert without issues on modern hardware.

  • Can I use this on mobile?

    Yes. The tool is responsive and works on smartphones and tablets.

  • Does the tool handle invalid JSON?

    The tool displays an "Invalid JSON" badge when the input is malformed. Fix the JSON and try again.

Featured Tools

Featured tools that you might find useful.

Popular Tools

List of popular tools that users love and frequently use.

New Tools

The latest tools added to our collection, designed for you.

Topics

The tools grouped by topics to quickly find what you need.
Free online Markdown to JSON converter. Choose from 4 data formats, set indent size, add root object, and minify output. Edit tables visually. Runs in browser.

Markdown To JSON

Free online Markdown to JSON converter. Choose from 4 data formats, set indent size, add root object, and minify output. Edit tables visually. Runs in browser.
Free online Markdown to JSONLines converter. Paste Markdown tables and generate JSONL format for BigQuery, LLM training, or data pipelines — runs in browser.

Markdown To JSONLines

Free online Markdown to JSONLines converter. Paste Markdown tables and generate JSONL format for BigQuery, LLM training, or data pipelines — runs in browser.
Free online Markdown to LaTeX table converter. Paste Markdown tables and generate LaTeX tabular code with 7 border styles and 10 settings — runs in browser.

Markdown To LaTeX Table

Free online Markdown to LaTeX table converter. Paste Markdown tables and generate LaTeX tabular code with 7 border styles and 10 settings — runs in browser.
Free Markdown to custom template converter. Transform Markdown tables into SQL, HTML, JSON, PHP, C, or any format using 18 built-in templates or your own syntax.

Markdown To Custom Template

Free Markdown to custom template converter. Transform Markdown tables into SQL, HTML, JSON, PHP, C, or any format using 18 built-in templates or your own syntax.