JSON to PHP Class
Paste JSON and get a typed PHP class with a constructor, nested classes for nested objects, and optional getter methods.
Input JSON
PHP Output
Paste JSON and click Generate
Copied!
Summary
Paste JSON and get a typed PHP class with a constructor, nested classes for nested objects, and optional getter methods.
How it works
- Paste or type a JSON object or array into the input panel, or load a sample.
- Set a root class name and, optionally, a namespace.
- Choose whether to generate private properties with getters, or public properties without them.
- Click Generate to parse the JSON and build the PHP class definitions.
- Nested objects become their own classes; arrays of objects are scanned across all items to detect fields that are not always present.
- Copy or download the generated PHP code.
Use cases
- Scaffold a typed DTO class from a sample API response.
- Turn a JSON config file into a typed PHP settings object.
- Generate value objects for a new project without typing every property by hand.
- Check which fields in a JSON array are optional across entries.
- Document a webhook payload shape as PHP classes for a codebase.
- Speed up adding typed properties to legacy code that reads raw JSON.
Frequently Asked Questions
Last updated: 2026-07-24 ·
Reviewed by Nham Vu