JSON to JSDoc Typedef
Generate JSDoc @typedef definitions from a JSON sample.
Overview
The JSON-to-JSDoc converter produces @typedef declarations from a sample JSON document. Each object becomes a typedef with @property lines describing every key, its type, and optional flag — so a JavaScript project without TypeScript can still get IDE autocomplete and type checking.
It's the right tool for vanilla JS codebases that want type hints without adopting a transpiler. Frontend developers using VS Code with JSDoc-driven IntelliSense, library authors documenting their object shapes, and teams gradually adopting types reach for a json to jsdoc converter to bootstrap type docs.
How it works
The generator walks the JSON tree and emits one @typedef block per object encountered. The root typedef gets a configurable name; nested objects get auto-generated names based on the property they live under, capitalised. Field types map to JSDoc syntax: string, number, boolean, Array<T>, and custom typedef names for nested objects.
Optional fields (null in the sample, or missing in some elements of an array) are marked with the JSDoc square-bracket optional notation: [user.email]. Nullable types use the ? prefix: ?string means the value may be string or null.
Examples
Sample:
{ "id": 1, "name": "Alice", "tags": ["admin","ops"], "address": { "city": "Berlin" } }
/**
* @typedef {Object} Root
* @property {number} id
* @property {string} name
* @property {Array<string>} tags
* @property {Address} address
*/
/**
* @typedef {Object} Address
* @property {string} city
*/
// Optional and nullable fields:
/**
* @typedef {Object} User
* @property {number} id
* @property {?string} email
* @property {string} [nickname]
*/
FAQ
Do modern editors actually use JSDoc types?
Yes. VS Code's JavaScript language service reads @typedef, @param, @property, and @returns to provide hover info, autocomplete, and error checking — effectively giving you TypeScript-quality tooling without a build step.
Can it produce TypeScript instead?
Use the JSON-to-TypeScript tool for native .ts interfaces. JSDoc is for projects that want to stay on plain .js files.
How are union types written?
JSDoc unions use |: {string|number}. The generator produces them when a sample shows mixed types across array elements or across multiple objects with the same key.