Web Development

A TypeScript definition for JSON data

JSON supports some primitive values: string, boolean, null, number. It also supports arrays and objects. To represent all of their various combinations, you can use the following as a type definition:

type JSON =
  | string
  | null
  | number
  | boolean
  | JSON[]
  | { [key: string]: JSON };

You'd think that you could use Record<string, JSON>, but the { [key: string]: JSON } workaround works instead. There's a lot of discussion about techniques people are using in this GitHub issue;