JSON to TypeScript

  • Optional keys
  • Nested types
  • Instant

Interfaces inferred from every array element, not just the first one.

Input
TypeScript

Paste input on the left to see typescript.

Everything runs in your browser — nothing is uploaded.

About typescript

Generating TypeScript from JSON produces interfaces matching a sample response. JSONic merges the shape of every array element rather than sampling only the first, so keys present in some objects but not others become optional properties instead of disappearing — the failure that makes most generated types unreliable.

Paste a JSON response and get TypeScript interfaces for it. Rather than sampling only the first array element, JSONic merges the shape of every element, so keys that appear in some objects but not others come out as optional properties instead of silently disappearing — which is the failure mode that makes generated types worse than useless.

Questions

How are arrays of mixed objects handled?

Every element is merged into a single shape. Keys missing from some elements are emitted as optional (key?: T) rather than dropped, so the type reflects what the data can actually contain.

What happens to null values?

A value that is null in the sample is typed as null, since the sample carries no information about what else it could be. Widen it by hand once you know the real type.

Are nested interfaces named sensibly?

They are named after their property in PascalCase, and de-duplicated with a numeric suffix if two different shapes would claim the same name.