JavaScript Class to JSON Schema Generator

Need JSON to JavaScript?

Turn JSON payloads into reusable JS objects.

JSON → JavaScript Objects

JavaScript code Input

Loading...

JSON Schema Output

Paste your JavaScript class definitions to produce JSON Schema instantly.

Supports ES6 classes with constructor assignments or class field syntax.

Frequently Asked Questions

What JavaScript code is supported?

Paste ES6 classes that assign fields in the constructor (this.field = value) or use class field syntax (field = value). The parser infers JSON Schema types from literal assignments such as strings, numbers, booleans, arrays, and object literals.

How accurate is the type inference?

Literal values set the schema type (for example, "" => string, 0 => integer, [] => array). Non-literal assignments fall back to string and are marked optional. Arrays become schema arrays with generic elements, and object literals become maps.

Does this work with TypeScript?

If your TypeScript classes include literal default values, the parser works as well, but for type annotations we recommend the TypeScript Class → JSON Schema tool. This JavaScript converter focuses on runtime assignments.

How can I get mock JSON from the schema?

After generating the schema, click "Generate Mock Data" to open the Mock Generator with the schema preloaded. Configure locales, array sizes, and optional fields to create example payloads in seconds.