json-types
JSON TypeScript Definitions
Last updated 6 years ago by robjtede .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install json-types 
SYNC missed versions from official npm registry.

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
  })
}

Current Tags

  • 1.0.2                                ...           latest (6 years ago)

3 Versions

  • 1.0.2                                ...           6 years ago
  • 1.0.1 [deprecated]           ...           6 years ago
  • 1.0.0 [deprecated]           ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (3)

Copyright 2013 - present © cnpmjs.org | Home |