JSON to JSDoc
Generate JSDoc typedefs from JSON for type-checked JavaScript
Paste JSON or load an example to generate JSDoc code.
How to use
- 1.Paste JSON, upload or drop a .json file, or load one of the examples.
- 2.Set the root typedef name and choose separate typedefs or inline nested objects.
- 3.Pick the optional style ([name] or {string=}) and the nullable style (string|null or ?string).
- 4.Under Advanced, keep or remove the export {} line that makes the file a module.
- 5.Read the notes under the output, then copy the JSDoc or download the .js file.
What JSON to JSDoc generates
JSON to JSDoc turns an API response or any JSON sample into JSDoc @typedef blocks that editors and the TypeScript checker understand in plain JavaScript files. Each object gets a named typedef with one @property per key, or nested objects can be written inline as { key: type } literals. It uses the same type inference as the other JSON-to-language generators on CodingTool, so optional, nullable and mixed values are detected the same way. The output describes types for your editor and type checker only; it does not validate data at runtime.
How types are mapped
- •Strings become string, integers and decimals become number (JSDoc has no integer type), and booleans become boolean.
- •Arrays become T[], or Array<(A|B)> when items mix types; other mixed values become a union such as (string|number).
- •Values that were always null and arrays that were always empty become *, because the sample shows no real type, and a note says so.
- •A top-level array of objects is read as several samples: a key missing from some objects becomes optional ([name]), a key that is sometimes null becomes nullable (string|null), and a RootList typedef describes the array.
- •Keys such as first-name stay as written. Keys with spaces, dots or a leading digit cannot follow @property, so that typedef becomes a record type with quoted keys.
- •An empty object becomes Object<string, *>. Typedefs are written root-first; JSDoc typedefs are hoisted, so the order is for reading only.
Limits and privacy
A sample shows what the data looked like once, not the full API contract, so review optional properties and * types before relying on them. JSDoc types are hints for editors and type checkers such as TypeScript with checkJs; they never check data at runtime. Input is limited to 5 MB and 256 nesting levels; from 2 MB, generation waits for the Generate button. Everything runs in your browser and the JSON is never uploaded.
Frequently asked questions
- How does the generator find optional properties?
- Paste a top-level array of objects and every object is read as a sample. A key that is missing from some samples becomes optional, written as [name] by default or with the Closure equals suffix, and a note lists how many samples lacked it. A key that is present but sometimes null becomes nullable instead.
- Will TypeScript and VS Code understand the output?
- Yes. The typedefs use JSDoc syntax that the TypeScript checker reads in JavaScript files with checkJs, and the test suite type-checks the output of every example and option combination with the TypeScript compiler. The optional export line makes the file a module so other files can import the typedefs.
- Is my JSON uploaded anywhere?
- No. Parsing, type inference and JSDoc generation run entirely in your browser, and the JSON is never sent to a server or stored.
