JSON to PHP Converter

Convert JSON to PHP
arrays online, free & instant

Paste your JSON and get valid PHP associative array syntax in one click. Handles nested objects, indexed arrays, and all data types. Runs entirely in your browser — no upload, no account, no waiting.

Open JSON to PHP Converter

From JSON to PHP array syntax in seconds

Paste your JSON Drop any JSON object or array into the input. Keys become PHP string keys, values map to their PHP equivalents.
Associative array output JSON objects become PHP associative arrays with the short [] syntax. Nested objects produce nested arrays with proper indentation.
All types supported Strings, integers, floats, booleans (true/false), null, indexed arrays, and deeply nested structures — all correctly converted.
Copy into your project One-click copy sends the PHP code to your clipboard. Paste it into Laravel configs, WordPress options, or any PHP file.

No account. No upload. No nonsense.

🔒

100% Private

Your JSON never leaves your device. There is no server receiving your data.

Instant Output

Conversion happens as you type. No round-trips to a backend, no latency.

🐘

PHP-Ready Code

Valid PHP syntax using short array [] notation — works in PHP 5.4+ and all modern frameworks.

Related JSON tools

JSON to Java Generate strongly-typed Java POJO classes from JSON with nested class support.
JSON to XML Convert JSON to well-formed XML with proper nesting and element mapping.
JSON to CSV Convert JSON arrays to spreadsheet-ready CSV files instantly.
JSON Formatter Pretty-print JSON with syntax highlighting and a collapsible tree view.

Common questions answered

Is the JSON to PHP converter free?

Yes, completely free with no account or signup required. The converter runs entirely in your browser.

How does JSON map to PHP arrays?

JSON objects become PHP associative arrays with string keys using the short array syntax []. JSON arrays become indexed PHP arrays. Strings, numbers, booleans, and null map directly to their PHP equivalents.

Is the output the same as json_decode in PHP?

Yes. The generated PHP array is equivalent to what json_decode($json, true) produces — an associative array representation. The difference is you get copy-pasteable PHP source code instead of a runtime call.

Can I use the output in Laravel or WordPress?

Absolutely. The generated PHP array syntax works in any PHP project — Laravel config files, WordPress options, Symfony parameters, or plain PHP scripts. Just paste it directly into your code.

Is my data sent to a server during conversion?

No. All conversion runs entirely in your browser using JavaScript. Your JSON is never uploaded or transmitted to any server.

Converting JSON to PHP arrays and classes

PHP represents JSON data as associative arrays (json_decode with true) or stdClass objects. This tool generates PHP code showing both: a typed class definition with PHPDoc annotations, and an associative array literal for direct use in scripts.

The converter generates PHP 8.0+ class definitions with typed properties, constructor promotion, and nullable types. JSON objects map to classes, arrays to array<int, T>, and primitives to PHP native types. Output includes PHPDoc @var annotations for IDE autocompletion and PHPStan analysis.

Convert JSON to PHP
Input
{
  "name": "Alice",
  "age": 30,
  "roles": ["admin"],
  "bio": null
}
Output
<?php
class Root {
    public function __construct(
        public string $name,
        public int $age,
        public array $roles,
        public ?string $bio,
    ) {}
}

// Or as array:
$data = [
    'name' => 'Alice',
    'age' => 30,
    'roles' => ['admin'],
    'bio' => null,
];

Get the most out of this tool

Ready to convert your JSON to PHP?

Free forever. No signup. Works offline.

Convert JSON to PHP now

JSON to PHP conversion explained

PHP has native JSON support through json_decode() and json_encode(), available since PHP 5.2. By default, json_decode() returns stdClass objects for JSON objects and arrays for JSON arrays. To get associative arrays instead of objects, pass true (or JSON_OBJECT_AS_ARRAY) as the second argument. This converter produces PHP array syntax — the format most useful for embedding JSON data directly in PHP code as a native data structure without parsing overhead.

PHP array syntax uses => for key-value association and square brackets (PHP 5.4+) or array() for the older syntax. JSON true becomes PHP true, JSON false becomes PHP false, and JSON null becomes PHP null. JSON numbers map to PHP int or float based on whether they have a decimal component. Strings use single quotes in the PHP output (PHP convention for non-interpolated strings) since JSON string values rarely contain single quotes that would require escaping.

For object-oriented PHP code, converting JSON to PHP class definitions provides type safety and IDE autocomplete. The converter can generate PHP classes with typed properties (PHP 7.4+), constructor promotion (PHP 8.0+), and attribute annotations. Each JSON object becomes a PHP class, and the converter produces __construct() parameters matching the JSON fields, making it straightforward to instantiate and pass around typed objects.

Laravel, the most popular PHP framework, uses JSON extensively. Eloquent models return JSON from APIs, Form Requests validate JSON inputs, and API Resources transform Eloquent models to JSON responses. Laravel's json() helper and response()->json() methods serialize PHP arrays and objects. The converted PHP arrays from this tool work directly with Laravel's Collection, Arr helper, and json_encode() calls throughout a typical Laravel application.

Symfony's Serializer component handles complex JSON-to-PHP-object deserialization with support for nested objects, arrays, and type coercion. It uses class annotations or PHP 8 attributes to define serialization behavior. When working with Symfony APIs, generating a PHP class structure from the JSON and then adding Symfony serializer attributes gives you a robust, validated deserialization pipeline for incoming JSON data.

PHP test fixtures frequently use JSON data to represent API responses or database records. Converting the JSON to a PHP array literal makes it easy to inline test data directly in PHPUnit tests without file loading or JSON parsing. The array literal is immediately readable in the test file, making tests self-documenting and fast to execute.

When developers use this tool

Laravel API response seeding Convert an external API's JSON response to a PHP array for use in Laravel factory definitions, seeder classes, or test fixtures — without parsing JSON at runtime during testing.
WordPress plugin development WordPress plugins that consume external APIs receive JSON responses. Convert the JSON structure to PHP arrays to understand the data shape before writing wp_remote_get() response parsing code.
Config file migration When migrating from JSON configuration to PHP configuration (common in Symfony and Laravel projects), convert the JSON config file to PHP array syntax as a starting point for the migration.
PHPUnit test data Convert JSON API mocks or webhook payloads to PHP array literals for use in PHPUnit data providers or as inline test variables, eliminating the need to read and decode JSON files in tests.

Additional frequently asked questions

What is the difference between json_decode with and without the associative flag?

Without the flag (or with false), json_decode returns stdClass objects for JSON objects — you access fields with arrow notation: $obj->name. With true (associative array mode), it returns PHP arrays — you access fields with bracket notation: $arr['name']. The converter generates associative array syntax, which is more common in PHP code.

How do I use the PHP array in a Laravel project?

Paste the PHP array directly into your PHP file. You can use it as a variable assignment, return it from a factory definition, or pass it to Illuminate\Support\Collection::make() to get a Laravel Collection for functional processing. It also works with Eloquent's fill() and create() methods for model hydration.

Does PHP maintain JSON key order in associative arrays?

PHP associative arrays maintain insertion order since PHP 7.0. When json_decode returns an associative array, the key order matches the JSON document order. This is important when you need to iterate the array in the same order as the source JSON, though for data access by key, order is irrelevant.

How should I handle very large JSON files in PHP?

PHP's json_decode() loads the entire JSON string into memory before parsing. For large files (tens of megabytes or more), use a streaming JSON parser like halaxa/json-machine. For moderate sizes (a few megabytes), increasing PHP's memory_limit in php.ini is often the simplest solution.