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

  1. Paste or type a JSON object or array into the input panel, or load a sample.
  2. Set a root class name and, optionally, a namespace.
  3. Choose whether to generate private properties with getters, or public properties without them.
  4. Click Generate to parse the JSON and build the PHP class definitions.
  5. Nested objects become their own classes; arrays of objects are scanned across all items to detect fields that are not always present.
  6. 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