Free JSON to PHP — array · stdClass · typed class

Convert JSON to PHP
array, stdClass
or typed class.

Generate PHP associative arrays, stdClass objects or typed PHP 8 classes from any JSON sample. Nested objects, nullable types, constructor promotion. Runs entirely in your browser.

Your data never leaves your browser
Array · stdClass · Typed class
Nested objects → separate classes
Constructor promotion (PHP 8+)
Always free
JSON to PHP Generator   100% client-side
Use a representative JSON sample with non-null values for accurate type inference. Null fields become ?mixed in typed class mode.
JSON input
  PHP ready

      
Array vs stdClass vs Typed class — which to choose

Three PHP output styles for three different use cases.

StylePHP versionAccess syntaxBest for
Array Any PHP version $data['key'] Most common PHP pattern. Equivalent to json_decode($json, true). Works with array functions (array_map, array_filter, etc.).
stdClass Any PHP version $data->key When you prefer object syntax. Equivalent to json_decode($json) without the true flag. Properties accessed with ->.
Typed class PHP 8.0+ $obj->getName() Modern PHP with strict typing. Constructor promotion, typed properties, IDE autocompletion. Best for domain models and DTOs.
How JSON types map to PHP types
JSON valuePHP typeNotes
"Alice"stringAll JSON strings become string.
42intJSON integers become int.
98.5floatJSON floats become float.
trueboolDirect mapping.
null?mixedNull fields become nullable mixed — refine manually after generating.
["a","b"]array<string>Item type inferred from first element. Empty → array<mixed>.
[{…}]array<ChildClass>Array of objects → separate class + typed array.
{…}ChildClassNested object → separate named class.
When do you need JSON to PHP?
Laravel and Symfony

Laravel and Symfony apps consume REST APIs and receive JSON payloads. Generate the PHP array or typed class from the API response JSON — then use it directly in your controller, service or repository. For Laravel, the typed class works perfectly as a DTO for FormRequest or API Resource output.

Configuration and fixtures

PHP config files are often arrays. Convert a JSON configuration file to a PHP array to use in a config/services.php or similar file — keeping JSON as the source of truth while generating the PHP equivalent for frameworks that require native PHP arrays.

PHPUnit test fixtures

PHPUnit tests need PHP arrays or objects that match your API response structure. Generate the PHP array from a real API response JSON — then use it as the expected value in your assertions or as the mock return value for a repository stub.

Third-party API integration

Integrating a payment gateway, shipping provider or CRM API? Generate typed PHP classes from the API documentation JSON examples — giving you IDE autocompletion, static analysis with PHPStan or Psalm, and type safety across the integration layer.

Popular searches
json to php array json to php convert json to php array json to php array online json to php class json to php object json to php online json to php array converter json to php associative array convert json to php online json to php model json to php typed class

PHP generated in
your browser. No upload.

The entire PHP generation runs in JavaScript locally. Your JSON is parsed and traversed entirely in your browser — it is never transmitted to any server. The generated code follows PHP 8 conventions: constructor promotion, typed properties, nullable syntax and array type hints.

The Array output is identical to what json_decode($json, true) returns at runtime — a nested associative array you can use with array functions, pass to views or store in session without any class instantiation.

3 output styles
Array, stdClass and typed PHP 8 class — covering every PHP version and coding style from legacy PHP 5 projects to modern PHP 8.2.
Constructor promotion
PHP 8 typed classes use constructor promotion — the most concise PHP 8 syntax, eliminating the need for separate property declarations.
Nested classes
Each nested JSON object generates a separate PHP class — no untyped arrays for nested data. Fully typed from root to leaf.
47 tools, always free
No file size limits, no watermarks, no account. Funded by non-intrusive display advertising only.
Frequently asked questions
Common questions about converting JSON to PHP.
How do I convert JSON to a PHP array?
Paste your JSON into the converter above, select the Array output style, and click Generate. The output is equivalent to json_decode($json, true) — a nested PHP associative array. Copy the array definition directly into your PHP code as a static fixture or config value.
How do I decode JSON in PHP at runtime?
Use json_decode(): $array = json_decode($json, true) for an associative array, or $obj = json_decode($json) for a stdClass object. Always check json_last_error() === JSON_ERROR_NONE after decoding. In PHP 7.3+, you can pass JSON_THROW_ON_ERROR as the flags parameter to throw a JsonException instead.
What is constructor promotion in PHP 8?
Constructor promotion lets you declare and assign class properties directly in the constructor signature — public function __construct(public string $name, public int $age) {} — instead of declaring properties separately and assigning them in the constructor body. It's the most concise way to write PHP data classes and DTOs.
Is the JSON to PHP converter free?
Yes, completely free. No file size limits, no account required. JSONshift is funded by non-intrusive display advertising.
Go up