Skip to content
XUtilHub

JSON to JavaScript – JSDoc Types & ES Classes

Generate JSDoc @typedef definitions or ES6 classes from JSON. Get editor autocomplete and type checking in plain JavaScript, no TypeScript needed.

  • Free, no sign-up
  • Runs in your browser, nothing uploaded
Input
Code

About the JSON to JavaScript

Generate JSDoc type definitions that give you autocomplete and type checking in plain JavaScript, or ES classes whose constructors build nested objects from raw JSON.

Key features

  • JSDoc @typedef definitions for editor autocomplete
  • Works with VS Code type checking (// @ts-check)
  • Or ES6 classes that build nested objects from raw JSON
  • Optional properties marked with [brackets]
  • Keys like "first-name" handled with object-literal types
  • No build step or TypeScript required

Types for plain JavaScript

Not every project uses TypeScript, but everyone benefits from autocomplete. JSDoc type definitions give JavaScript editors the same knowledge of your data's shape, with zero build tooling. Or generate ES6 classes that turn raw JSON into model objects you can extend with methods.

JSDoc example

/**
 * @typedef {Object} Root
 * @property {number} id
 * @property {string} name
 * @property {Address} address
 * @property {string} [nickname]
 */

/** @type {Root} */
const user = await (await fetch("/api/user")).json();
user.address.city; // autocompleted

Class example

export class Root {
  /** @param {Record<string, any>} data */
  constructor(data) {
    /** @type {number} */
    this.id = data.id;
    /** @type {Address} */
    this.address = new Address(data.address);
  }
}

Which output should I choose?

NeedChoose
Autocomplete and type checking onlyJSDoc @typedef
Models with methods (e.g. fullName())ES6 classes
Smallest footprintJSDoc (comments only, no runtime code)

Enable type checking

Add this to the top of a file:

// @ts-check

or set "checkJs": true in jsconfig.json to check the whole project.

Prefer TypeScript? Use JSON to TypeScript. Inspect your data first with the JSON Viewer.

How to use the JSON to JavaScript

  1. Paste your data into the input box, upload a file, or click Sample to try it out.
  2. Adjust the options above the editor if you need to (indentation, delimiter, and so on).
  3. The JavaScript appears instantly in the output panel. Any errors are shown with their line and column.
  4. Click Copy to copy the result, or Download to save it as a file.

Frequently asked questions

How do I use the JSDoc types?

Paste them into a .js file and annotate variables with /** @type {Root} */. VS Code and other editors then give you autocomplete, and adding // @ts-check at the top enables type errors.

What do the ES6 classes do?

Each class's constructor takes the raw JSON object and copies its fields, constructing nested class instances for objects and arrays of objects, so you can add methods to your models.

Do I need TypeScript installed?

No. JSDoc types are understood by the TypeScript language service built into VS Code, WebStorm and other editors, even in plain JavaScript projects.

Why camelCase in classes but original keys in JSDoc?

JSDoc types describe the JSON exactly as it arrives. The classes are your own objects, so they follow JavaScript naming conventions.

Is my JSON uploaded to a server?

No. All JSON tools run entirely in your browser, so your data never leaves your device.

Is there a size limit?

There is no fixed limit. Files of several megabytes work fine; very large files depend on your device's memory.

Do I need an account?

No. Every JSON tool is free and works without signing up.

Last updated:

Related JSON tools