Skip to content

Instantly share code, notes, and snippets.

@mr-moon
Created December 16, 2024 10:46
Show Gist options
  • Save mr-moon/e2d073fa7899d2aaedd55f739b50a778 to your computer and use it in GitHub Desktop.
Save mr-moon/e2d073fa7899d2aaedd55f739b50a778 to your computer and use it in GitHub Desktop.
A TypeScript type to deserialize JSON in a semi-safe way.
type Primitive =
| bigint
| boolean
| null
| number
| string;
type JSONValue = Primitive | JSONObject | JSONArray;
type JSONArray = Array<JSONValue>;
export type JSONObject = Primitive | JSONArray | {
[key: string]: JSONValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment