ConvertersLesson 28Free preview
JSON to TypeScript
This lesson is part of Web Developer Tools · All levels
Summary
The JSON to TypeScript converter produces an interface declaration or type that describes the JSON data form. Objects become interfaces with typed properties, arrays become array types, and clustered objects can become separate interfaces. Properties that do not always appear on the sample can be optionally marked with a question mark. The type generated is only a guess from the data sample, so it remains necessary to review and adapt to the actual API contract.
Key points
- Converts JSON structure to an interface or TypeScript type
- Arrays are typed as string[] or Interface[]
- The object cluster can be broken down into its own interface
- Optional property marked with question mark (?)
- The result of the converter is based on a sample and not a runtime validation
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.