JSON to JSDoc Comments Converter — Numio
Builds a JSDoc @typedef comment with one @property line per key from a JSON sample. Nested keys use dot paths such as address.city, keys of array items name[].key, and optional keys [brackets].
Getting editor autocompletion for an API response in a plain JavaScript project.
JSON
JSDoc
When to use it
- Getting editor autocompletion for an API response in a plain JavaScript project.
- Enabling // @ts-check type checking for JSON data without moving to TypeScript.
How to use
- Paste a JSON object into the editor.
- Check the @property lines on the right: types come from the sample values, for example string[] for tags and object for address.
- Copy the comment, rename the typedef from json to a real name, and use it with @type {YourName}.
JSON input
{
"id": 42,
"name": "Ada",
"tags": ["math", "poetry"],
"address": { "city": "London", "zip": "NW1" },
"orders": [
{ "sku": "A1", "qty": 2 },
{ "sku": "B7", "qty": 1, "gift": true }
],
"deletedAt": null
}JSDoc @typedef
/**
* @typedef {object} json
* @property {number} id
* @property {string} name
* @property {string[]} tags
* @property {object} address
* @property {string} address.city
* @property {string} address.zip
* @property {object[]} orders
* @property {string} orders[].sku
* @property {number} orders[].qty
* @property {boolean} [orders[].gift]
* @property {null} deletedAt
*/Details and limitations
The comment is generated in your browser; no data is sent to a server. There are no settings.
All items of an array are merged: keys missing from some items are written in square brackets as optional, such as [orders[].gift].
A value that is only null is typed {null}; null next to real values gives a union such as {string|null}. Empty arrays are typed {Array}.
Keep IDs such as 001 as strings in the input; once parsed as numbers the leading zeros are lost.
FAQ
How are arrays of objects documented?
The array is typed object[] and the item keys are listed with name[].key paths, such as orders[].sku, combining the keys of all items.
Can I convert a JSON array at the root?
Yes. The item shape becomes @typedef {object} jsonItem with its properties, followed by @typedef {jsonItem[]} json for the array.
Does TypeScript understand the generated typedef?
Yes, TypeScript reads @typedef with nested @property paths in .js files when checkJs or // @ts-check is enabled. Replace a bare {null} with the real type first.