JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 23297
  • Score
    100M100P100Q128331F
  • License MIT

Type checking for JSON objects

Package Exports

  • types-json

Readme

types-json

NPM TypeScript Coverage Status

Types and type guards for JSON values.

If I should maintain this repo, please ⭐️ GitHub stars

DM me on Twitter if you have questions or suggestions. Twitter


This package is specifically for when you have a value that you know is valid JSON - ex: the result of JSON.parse.

It includes type guards for each of the JSON types, as well as matching types.

Installation

yarn add types-json
npm install types-json
pnpm add types-json

Usage

import {
  isJSONValue,
  isJSONObject,
  isJSONArray,
  isString,
  isNumber,
  isBoolean,
  isNull,
  isUndefined
} from "types-json";

isJSONObject({}); // true
isJSONArray([]); // true
isString("foo"); // true
isNumber(1); // true
isBoolean(true); // true
isNull(null); // true
isUndefined(undefined); // true

isJSONValue(undefined); // false

Types

import {
  JSONObject,
  JSONValue,
  JSONArray
} from "types-json";

type JSONObject = {
  [key in string]?: JSONValue
};

type JSONValue = string | number | boolean | null | JSONObject | JSONArray;

interface JSONArray extends Array<JSONValue> {};

Dev Dependencies

  • autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.

License license

MIT