Report Tool or Give Us Suggestions

JSON to JavaScript POJO Generator

Generate JavaScript ES6 classes from JSON samples with constructor and toJSON in the browser.

L ading . . .

Generate JavaScript ES6 classes from any JSON sample with a typed constructor, a static fromJSON() factory, and a toJSON() serializer. Paste your JSON, choose a root class name, and the tool walks the parsed shape to emit one class per nested object—completely client-side.

What the tool generates

  • ES6 class definitions with destructuring constructors so you can build instances from plain objects.
  • JSDoc type annotations on each property using @type for editor autocomplete and type-aware tooling.
  • static fromJSON(data) factory that safely rebuilds an instance and recursively rebuilds nested classes and arrays of classes.
  • toJSON() method that returns a plain object with the original JSON keys preserved—ideal for JSON.stringify.
  • CommonJS module.exports listing every generated class so the file is drop-in ready for Node.js projects.

Why use POJO classes in JavaScript?

Plain old JavaScript objects work everywhere, but wrapping them in classes gives you discoverable methods, JSDoc-driven autocomplete in VS Code, and a clear contract between layers of your application. The generated fromJSON/toJSON pair is enough for round-tripping payloads through fetch, localStorage, queues, or worker messages without losing the type information you can see in your editor.

Type inference

  • true / falseboolean
  • Integer values → number (int) JSDoc tag
  • Decimal numbers → number (float) JSDoc tag
  • Strings → string
  • Objects → nested ES6 class
  • Arrays → Array<T> typed by the first non-null element
  • Null and undefined → any

Identifier safety

JSON keys are converted to camelCase for property and constructor parameter names. JavaScript reserved words (such as class, delete, new) are suffixed with Value so the class compiles cleanly. The original JSON keys are preserved in toJSON() output so serialization round-trips unchanged.

Known limitations

Heterogeneous arrays infer their item type from the first non-null element. null/undefined values fall back to any. If your JSON contains keys that are not valid JS identifiers (for example "first-name"), the output uses bracket access and quoted keys to preserve them.

Frequently Asked Questions

Are the generated classes plain JavaScript or TypeScript?

They are plain JavaScript ES2015+ classes. Type information is conveyed through JSDoc @type annotations so editors like VS Code provide autocomplete without requiring a TypeScript build step.

Do nested objects get their own class?

Yes. Each nested object becomes its own class named after the parent class and the property. fromJSON() recursively rebuilds nested classes and arrays of classes; primitive arrays are shallow-copied.

Can I use the output with JSON.stringify?

Yes. JSON.stringify automatically calls toJSON() on each instance, so passing a top-level instance produces the original JSON shape unchanged.

Is my JSON uploaded anywhere?

No. Parsing and code generation run entirely in your browser. Nothing is sent to any server.

Can I use the classes in ES Modules?

Yes. Replace the trailing module.exports = { ... } with export { ... } if you target ES module bundles. The class bodies themselves work in both module systems.