json-types
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Deprecation Notice

As of TypeScript 3.7, it's no longer necessary to use the workaround in this package for defining valid JSON structures.

This small snippet is all that is required now:

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

json-types

JSON TypeScript Definitions

A simple typescript definition module that simplifies type checking for valid JSON objects. Useful for defining interfaces and parameter type checking.

Installation

npm i json-types

Usage

import {
  Primitive,
  JSONEntry,
  JSONArray,
  JSONMap,
  JSONData
} from '../json-types'

Use Case

import {
  Primitive,
  JSONEntry,
  JSONArray,
  JSONMap,
  JSONData
} from '../json-types'
 
interface QueryString {
  [key: string]: Primitive | undefined
}
 
interface APIResponse extends JSONMap {
  address: {
    house_no: number
    street: string
  }
  name: string,
  has_website: false
  files: JSONArray
  metadata: JSONEntry
}
 
function httpGet (url: string): Promise<JSONData> {
  return requestPromise(url, {
    json: true
  })
}

Package Sidebar

Install

npm i json-types

Weekly Downloads

807

Version

1.0.2

License

MIT

Unpacked Size

4.82 kB

Total Files

8

Last publish

Collaborators

  • robjtede