@infra-blocks/json

0.1.2 • Public • Published

ts-json

Build Release Update From Template codecov

JSON related utilities package. It offers thin wrappers over JSON.parse and JSON.stringifiy and convenient types.

import { Json, JsonObject, JsonArray, JsonPrimitive, json } from "@infra-blocks/json";

// Convenient types can be used anywhere useful.
const validJson: Json = { key: "value" };
// @ts-expect-error
const invalidJson: Json = { "undefined is not json": undefined };

// The module offers a thin wrapper that returns a type Json value when parse is used without revivers.
const result: Json = json.parse('"finally, JSON.parse does not return any anymore"');
// Type of anyResult is any, since we used a reviver.
const anyResult = json.parse('{"key": "value"}', () => { /* Insert code here */ });
// The module also offers a stringify function, although it is exactly the same as JSON.stringify. It's mostly
// for completeness.
const stringified = json.stringify(new Map()); // Tolerates non Json typed object, just like the original function.

Package Sidebar

Install

npm i @infra-blocks/json

Weekly Downloads

89

Version

0.1.2

License

ISC

Unpacked Size

9.59 kB

Total Files

21

Last publish

Collaborators

  • phil-lavoie