Paste PHP on the left and click "Convert": we will turn it into JSONPaste PHP code

What this tool does

Say your PHP codebase has an Order class with constructor-promoted properties, and the mobile team wants a JSON body for their mocks. Writing that array out by hand means retyping every property name and getting the nesting right. Paste the class plus a new Order(...) call here instead and read the JSON off the right panel. A single DTO, a file of Doctrine entities, a Laravel Eloquent model or a bare associative array all go through the same way.

The converter matches what json_encode() does at runtime. Typed properties (PHP 7.4+) and readonly properties (PHP 8.1+) come out as ordinary JSON keys. Integers, floats, booleans, and strings map one-to-one. null becomes JSON null. Nested object instances are expanded into nested JSON objects. Associative arrays become JSON objects; numerically indexed arrays become JSON arrays: the same split json_encode makes.

PHP 8 syntax is fine. A backed enum such as OrderStatus::Paid shows up as its backing value, "paid", which is also what json_encode() prints for a BackedEnum. A DateTimeImmutable is written as an ISO-8601 string; note that a bare json_encode() call in production gives you a {"date": ..., "timezone_type": 3, "timezone": ...} object instead, so implement JsonSerializable if you need the string there too. Several classes in one paste, say a package you pulled from Packagist, each get a key of their own. Methods, class constants and static properties hold no instance data, so they are left out.

How to use it

Paste, convert, copy. The Order sample is a fair test: an enum, two value objects and a list of line items in one file.

1

Paste your PHP (or try the sample)

Put the PHP in the left editor, <?php tag and all. A class with promoted constructor properties, a new call with named arguments, an associative array or several classes together are all accepted. Load Sample fills the editor with an Order that uses readonly properties and an OrderStatus enum.

Keep the full PHP syntax: namespaces, use statements, visibility modifiers, attributes. The parser ignores the boilerplate it does not need.

2

Hit Convert

Press Convert. The code is posted to the backend, which works out the value each property ends up with (including the ones passed as named arguments) and returns them as JSON. A "Converting..." overlay covers the editors until the answer arrives; an empty editor just gets a reminder to paste some PHP.

3

Copy the JSON

Whatever comes back lands in the right editor. Select it and paste it into a Guzzle request body, a PHPUnit data provider, a Laravel factory or the example block of your API docs. If the reply could not be read as JSON, the error is shown with the raw text underneath so you can repair it by hand.

When this actually comes in handy

Building API request payloads

You have a CreateOrderRequest DTO and need the matching JSON body for Postman, curl, or an integration test. Paste the class, get the payload.

Seeding Laravel or Symfony

Turn a bunch of <code>new Product(...)</code> factory lines into a JSON seed file for database:seed or fixtures loaders, no more hand-crafted arrays.

Keeping OpenAPI examples honest

Generate JSON examples for your OpenAPI spec directly from your actual DTOs, so the schema examples stay in sync with your code.

Debugging json_encode output

When an object is not serializing the way you expect, paste it here to see the clean shape, then compare against what <code>json_encode()</code> is actually producing.

Common questions

Does it handle PHP 8 typed and readonly properties?

Yes. Typed properties, nullable types (?string), readonly modifiers, and promoted constructor properties are all picked up. The type hint does not change the JSON value: it just tells the parser what to expect.

What about enums?

Backed enums serialize to their backing value (string or int). Pure enums without a backing type are emitted as the case name. This matches the standard json_encode behaviour on a BackedEnum.

Associative array vs indexed array, which becomes an object?

Same rule as json_encode: a 0-indexed sequential array becomes a JSON array; any array with string keys (or non-sequential integer keys) becomes a JSON object.

How are DateTime and DateTimeImmutable serialized?

As ISO-8601 strings, the same format you get from $dt->format(DateTime::ATOM). If your date happens to include a timezone, the offset is preserved in the output.

Can I paste a whole models file?

Yes. Each top-level class gets an entry, and objects held in properties (an Address inside an Order, say) are expanded in place. Promoted constructor parameters count as properties. Private and protected ones are emitted as well, which differs from json_encode(): that function only sees public properties unless the class implements JsonSerializable.

Is my code stored?

The PHP is sent to the backend so it can be converted, and the payload is not saved or logged. Strip API keys or .env values out of the snippet before you paste; the converter only needs the shape.

Other tools you may need

Going back to PHP classes, or checking the JSON before it goes into a request, is covered here: