PHP Class to JSON Schema Generator

Need JSON to PHP?
JSON → PHP Classes

PHP code Input

Loading editor…

JSON Schema Output

Settings

Select which PHP class should be treated as the root when generating the schema.

Parsing runs entirely in your browser. Your source never leaves the page.

Paste your PHP classes to produce a JSON Schema instantly.

Supports typed properties, DocBlock annotations, nullable/union types, arrays, and associative maps.

How to convert PHP classes to JSON Schema – step-by-step guide

This online PHP class to JSON Schema converter helps you generate JSON Schema from real models (DTOs, structs, and classes) so you can validate payloads, share contracts, and generate mock JSON.

  1. Step 1 – Paste your PHP source

    • Paste the models you want to document into the left editor.
    • Include referenced types in the same snippet so the schema can generate definitions.
    • Use the Sample button to load an example and see the expected input format.
  2. Step 2 – Select the Root class (if needed)

    • If multiple definitions are detected, choose the root that matches your API payload.
    • The output schema is built around the selected root and may include additional definitions for referenced types.
  3. Step 3 – Review the JSON Schema output

    • Check types, required vs. optional fields, and nested object/array structures.
    • Look for definitions and $ref when your models reference other models.
    • Copy or download the schema for validation, documentation, or schema-first development.
  4. Step 4 – Validate or generate mock JSON

    • Click Generate Mock Data to open the mock generator with your schema preloaded.
    • Validate real payloads against your schema to catch breaking changes early.
    • If you rely on advanced schema composition (for example anyOf/oneOf/allOf), verify the result with a full validator like Ajv.

Schema keyword support note

Generated schemas can include $ref and may be edited to include anyOf, oneOf, or allOf. For complex schemas, use a full JSON Schema validator and dereference before mock generation if needed.

Related JSON Schema & code generation tools

Use these tools to validate schemas, generate mock payloads, format JSON examples, and keep code and contracts in sync.

Frequently Asked Questions

What PHP syntax is supported?

The converter reads class definitions with typed properties or DocBlock @var annotations, recognizing visibility modifiers, nullable types, arrays, and DateTime/UUID hints. Properties tagged as json-ignore or JsonIgnore are skipped automatically.

How are PHP types mapped to JSON Schema?

string, int, float, bool, array, and custom classes map to their JSON Schema counterparts. Nullable and union types mark fields optional, arrays become schema arrays, and array<string, T> patterns are treated as maps. Unknown classes fall back to string unless another PHP class with that name is defined.

Does it work with frameworks like Laravel or Symfony?

Yes. You can paste DTOs, form requests, or entity classes with typed properties or DocBlock hints. The tool runs entirely in your browser, so your code never leaves your machine.

How can I generate mock JSON data?

After generating the schema, click "Generate Mock Data" to open the Mock Generator with the schema preloaded. Configure locales and options to create sample payloads for docs or tests.

Convert PHP Classes to JSON Schema Online | JSONSwiss