JSPM

@hyperjump/json

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

JSON parser and stringifier with JSON Pointer support

Package Exports

  • @hyperjump/json

Readme

Json

This is a reimplementation of the builtin JSON object to add JSON Pointer parameters to the "reviver" and "replacer" functions. Other than the added parameters, the interface is the same as the original.

Installation

Includes support for node.js JavaScript (CommonJS and ES Modules), TypeScript, and browsers.

npm install @hyperjump/json

Usage

const Json = require("@hyperjump/json");

const subject = `{
  "type": "object",
  "properties": {
    "foo": { "type": "string" },
    "bar": { "$ref": "#/$defs/number" }
  },
  "required": ["foo", "bar"],

  "$defs": {
    "number": { "type": "number" }
  }
}`;
const result = Json.parse(subject, (key, value, pointer) => {
  console.log("REVIVER", pointer, key, JSON.stringify(value));
  return value;
});

const json = Json.stringify(result, (key, value, pointer) => {
  console.log("REPLACER", pointer, key, value);
  return value;
}, "  ");

Contributing

Tests

Run the tests

npm test

Run the tests with a continuous test runner

npm test -- --watch