JSON to TS
Paste a JSON sample and get TypeScript interfaces that describe it, nested types included.
export interface User {
id: number;
name: string;
active: boolean;
profile: Profile;
tags: string[];
posts: Post[];
}
export interface Profile {
url: string;
avatar: null;
}
export interface Post {
slug: string;
views: number;
pinned?: boolean;
}Every element of an array is inspected, not just the first: a key that is missing from some elements comes out optional, and mixed values come out as a union. Nested objects get their own interface named after their key, numbered on collision. Empty arrays become unknown[].
Typing an API response by hand is tedious and error-prone, particularly when it is deeply nested or has arrays of objects several levels down.
The sample is analysed and interfaces are generated for every level, with nested objects extracted into their own named types and arrays typed from their contents. Values that are null or absent are handled as optional rather than typed away.
What people open it for
- Generating types for an API response you just captured
- Bootstrapping types for a config file's shape
- Turning a fixture into an interface for a test
In the terminal
tools jsonts
Every utility is also a command in the desktop's shell.