JSON to PHP Class

Paste JSON and get a typed PHP class with a constructor, nested classes for nested objects, and optional getter methods.

Use the JSON to PHP Class

Input JSON

PHP Output

Paste JSON and click Generate

Copied!

Summary

JSON to PHP Class reads a JSON object or array and generates a matching PHP class definition with typed properties, a constructor, and (optionally) getter methods. Nested objects become their own named classes, and fields that are missing from some entries of an array are marked nullable so the generated code stays accurate instead of assuming every field is always present. Everything runs in your browser; the JSON never leaves your device.

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-14 · Reviewed by Nham Vu