Skip to content
AZ Tools

JSON to JSDoc @typedef Generator

Turn a JSON object into JSDoc @typedef blocks with @property tags, in your browser.

JSDoc typedefs

How to use

  1. Paste or type your JSON into the input box.
  2. Optionally rename the root typedef (defaults to Root).
  3. Copy the generated @typedef blocks into your JavaScript source.

About this tool

Show

Paste any JSON object or array and get JSDoc @typedef blocks with an @property line per field and a separate typedef for each nested object. This is how you add real type checking to plain JavaScript without adopting TypeScript or a build step: editors read JSDoc for autocomplete and inline errors, and the TypeScript compiler will check the same annotations when you turn on checkJs. Fields are mapped to string, number, boolean and array types; a null or an empty array becomes the any type, because a single sample cannot show what belongs there. Every property is generated as required, so wrap the optional ones in square brackets, which is how JSDoc marks them. Everything runs locally in your browser — your JSON is never uploaded.

Frequently asked questions

How are types mapped?

Strings become string, all numbers become number, booleans become boolean, and arrays become type[] based on their first element. Nested objects each get their own @typedef and are referenced by name.

What about null or empty arrays?

Their type can't be inferred from the sample, so null maps to * (any) and an empty array maps to *[]. Tighten these by hand if you know the real type.

Why JSDoc instead of TypeScript?

JSDoc @typedef lets you document and type-check plain JavaScript (for example with VS Code or tsc --checkJs) without adding a build step or .ts files.

Is my JSON sent anywhere?

No. Conversion happens entirely in your browser; nothing is uploaded.

How do I actually get the type checking, not just the comment?

Add // @ts-check at the top of the file, or checkJs to your tsconfig, and let the TypeScript compiler run over the JavaScript. Without one of those, JSDoc is documentation your editor may use for autocomplete but nothing enforces. With it, you get most of TypeScript's checking and no build step at all.

How do I mark a property as optional?

Wrap the name in square brackets: @property {string} [nickname] means the key may be absent. A default goes inside them too, as [role="user"]. Everything here is generated as required, because a single sample cannot show which keys the source may omit.

Related tools