JSON to PHP Class Converter
Turn a JSON sample into a PHP class in your browser. Optional and nullable fields are kept apart, and nothing is uploaded.
What the JSON to PHP generator does
Each object becomes a class with typed properties. A key that is absent from some array elements is declared with a leading question mark and a null default, because array is not a nullable type on its own. A field whose type varied is mixed, which already includes null, so it is never written as ?mixed — that syntax does not exist.
How to use it
JSON to PHP Class Converter: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the PHP class below.
Worked example
Input:
{
"orderId": "A-1001",
"total": 129.99,
"currency": "EUR",
"paid": false,
"customer": {
"email": "[email protected]"
},
"lines": [
{
"sku": "X1",
"qty": 2
},
{
"sku": "X2",
"qty": 1,
"discount": 0
}
]
}
Output:
<?php
// Generated from a JSON sample in the browser by AllTools — nothing was uploaded.
// Rename and adjust to taste; the shape is inferred from one example, not a schema.
class Root
{
public string $orderId;
public float $total;
public string $currency;
public bool $paid;
public Customer $customer;
public array $lines;
}
class Customer
{
public string $email;
}
class Line
{
public string $sku;
public int $qty;
public ?int $discount = null;
}
Why it runs in your browser
The conversion happens on this page with JavaScript. Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere. The page reads JSON and returns PHP class; reloading the page discards both.
Each object becomes a class with typed properties. A key that is absent from some array elements is declared with a leading question mark and a null default, because array is not a nullable type on its own. A field whose type varied is mixed, which already includes null, so it is never written as ?mixed — that syntax does not exist.
Turn a JSON sample into a PHP class in your browser. Optional and nullable fields are kept apart, and nothing is uploaded.
How to use it
JSON to PHP Class Converter: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the PHP class below.
Why it runs in your browser
The conversion happens on this page with JavaScript. Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere. The page reads JSON and returns PHP class; reloading the page discards both.
What to Expect
Best for
- Converting JSON to PHP class when the data is already on screen.
What this tool keeps
- Your input is not posted to a server, so it works offline after the page loads and nothing is retained anywhere.
Sample input
{ "orderId": "A-1001", "total": 129.99, "currency": "EUR", "paid": false, "customer": { "email": "[email protected]" }, "lines": [ { "sku": "X1", "qty": 2 }, { "sku": "X2", "qty": 1, "discount": 0 } ] }
Sample output
<?php // Generated from a JSON sample in the browser by AllTools — nothing was uploaded. // Rename and adjust to taste; the shape is inferred from one example, not a schema. class Root { public string $orderId; public float $total; public string $currency; public bool $paid; public Customer $customer; public array $lines; } class Customer { public string $email; } class Line { public string $sku; public int $qty; public ?int $discount = null; }
Frequently asked questions
How do I use the json to php class converter?
JSON to PHP Class Converter: paste the JSON into the box above, set Root type name (default "Root"), and press Run to get the PHP class below.
Is my input uploaded?
No. The text is parsed on this page with JavaScript and is never posted to a server.
Is there a size limit?
Yes: 5 MB per run. Larger input is refused with a message rather than freezing the tab.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.