JSON to PHP
Paste or drop your data here, or open a file.
New to Bracely?
Everything stays in your browser.
Output appears here
Paste or open your data in the input box. It never leaves your browser.
JSON to PHP
Paste a JSON sample, such as an API response, and Bracely writes PHP classes with typed properties for it. Each object becomes a final PHP class with constructor property promotion and strict types.
Example: a webhook payload for a Laravel or Symfony app
A shipment webhook with a nested tracking object. Each object becomes a final class with promoted, typed constructor properties under strict_types, the list of events gets its element type in a @var docblock, and delivered_at, missing from the first event, becomes nullable:
Input
{
"shipment_id": "SHP-5512",
"carrier": "BlueDart",
"tracking": {
"number": "BD123456789IN",
"url": "https://track.example.com/BD123456789IN"
},
"events": [
{
"status": "picked_up",
"at": "2026-10-28T09:00:00Z"
},
{
"status": "delivered",
"at": "2026-10-29T15:20:00Z",
"delivered_at": "2026-10-29T15:20:00Z"
}
],
"cod": false
}Output
<?php
declare(strict_types=1);
final class ShipmentUpdate
{
public function __construct(
public string $shipmentId, // json: "shipment_id"
public string $carrier,
public Tracking $tracking,
/** @var Event[] */
public array $events,
public bool $cod,
) {}
}
final class Tracking
{
public function __construct(
public string $number,
public string $url,
) {}
}
final class Event
{
public function __construct(
public string $status,
public string $at,
public ?string $deliveredAt = null, // json: "delivered_at"
) {}
}
How do I use the JSON to PHP?
- Paste a JSON sample.
- Set the root type name, for example Order.
- Copy the PHP code into your project.
What does the JSON to PHP do?
- declare(strict_types=1) and typed properties
- Array element types in @var docblocks
- Nullable types for optional fields
- Nested objects become their own named types
- 20 other languages from the same sample, including TypeScript
When to use the JSON to PHP
Laravel and Symfony apps, WordPress plugins and plain PHP services receive JSON from webhooks and APIs as nested arrays, which are easy to mistype. Typed classes catch a wrong key or type early and give your editor autocompletion. Paste a real payload and copy the classes.
Each object becomes a final class under declare(strict_types=1) with promoted, typed constructor properties (PHP 8.0 and later). snake_case keys become camelCase properties with the JSON key in a comment, arrays get their element type in a /** @var Event[] */ docblock for static analysers such as PHPStan and Psalm, a field missing from some items becomes nullable with a null default, and mixed values become mixed.
Frequently asked questions
- How do I fill the classes from json_decode?
- Pass the decoded values to the constructor, or use a mapper such as Symfony Serializer, Valinor or spatie/laravel-data, which can read the types and the @var docblocks.
- Why is the array element type in a comment?
- PHP has no typed arrays, so the property is array and the element type goes in @var. PHPStan, Psalm and IDEs read it and check what's in the array.
- How does it pick PHP types?
- From the values in your sample: whole numbers, decimals, text, true/false, arrays and nested objects. When array items disagree, the field is made optional or widened.
- Can I generate other languages?
- Yes. Change Language to any of the others: TypeScript, Go, Python, Pydantic, Java, C#, Kotlin, Swift, Rust, Scala, Ruby, Dart, Zod, TypeBox, Valibot, Yup, GraphQL, Protobuf, Prisma and Drizzle.
- Is my data uploaded?
- No. Bracely runs entirely in your browser, so nothing you paste or open leaves your device.
More JSON tools
Bracely has 108 JSON tools in one page. Related ones:
- JSON to Zod
- JSON to GraphQL
- JSON to Protobuf
- JSON to Pydantic
- JSON to TypeBox
- JSON to Valibot
- JSON to Yup
- JSON to Prisma
- JSON to Drizzle
- JSON to Scala
- JSON to Ruby
- JSON Schema builder
- JSON Schema validator
- JSON data dictionary
- cURL to code
- GraphQL request
- Mock JSON generator
- UUID generator
- SVG to JSX
- CSS to Tailwind
- JSON Formatter
- JSON Validator
- JSON Viewer
- JSON Repair
- JSON Diff
- JSON to YAML
- JSON to CSV
- jq Playground
Runs entirely in your browser. Nothing you paste is uploaded. Made by Saurabh Pagrut · About · Privacy policy
Last updated · Version 6.7 · Changelog
Saurabh Pagrut on GitHub · LinkedIn · X · YouTube · Instagram