JSPM

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

Next JSON format

Package Exports

  • next-json
  • next-json/dist/cjs/index.js
  • next-json/dist/es/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (next-json) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

NJSON - next-json

Next JSON format

Build Status Code Climate Test Coverage

NPM version NPM downloads Stars

Types Dependents Donate

Why this package?

Because JSON is awesome, but...

JSON is awesome mainly for two reasons:

  1. it offers an easy way to serialize complex data;
  2. a valid JSON encoded string can be pasted in a JavaScript source file, a really awesome feature while developing / debugging.

... but it has some limitations:

  • do not supports undefined values,
  • do not supports BigInt numbers,
  • do not supports many other features...

This package is intended to offer something as great as JSON... trying to add something more.

NJSON Features

  • ☑ extends JSON
  • ☑ supports C style comments
  • ☑ supports undefined values
  • ☑ supports BigInt numbers
  • ☑ supports Date objects
  • ☐ supports Error objects
  • ☐ supports circular references

NJSON extends JSON

This doesn't mean it's 100% compliant: due its higher number of supported features the result string of the serialization through NJSON.stringify may differs from the result of the serialization through JSON.stringify.

On the other hand, the result of the deserialization of a valid JSON encoded string through NJSON.parse will produce a value deep equal to the value produced by JSON.parse.

Installation

With npm:

npm install --save next-json

Usage

import { NJSON, NjsonParseOptions, NjsonStringifyOptions } from "next-json";

const serialized: string = NJSON.stringify({ some: "value" });
const deserialized: { some: string } = NJSON.parse<{ some: string }>(serialized);

NJSON.parse(text[, reviver])

Just for compatibility with JSON.parse. Alias for:

NJSON.parse(value, { reviver });

NJSON.parse(text[, options])

NJSON.stringify(value[, replacer[, space]])

Just for compatibility with JSON.stringify. Alias for:

NJSON.stringify(value, { replacer, space });

NJSON.stringify(value[, options])

interface NjsonParseOptions

  • reviver: <Function> Alters the behavior of the deserialization process. Default: null.

reviver

As the reviver parameter of JSON.parse.

interface NjsonStringifyOptions

date

Specifies the method of Date objects used to serialize them. Follows the list of the allowed values and the relative method used.

  • "iso": toISOString
  • "string": toString
  • "time": getTime - the default
  • "utc": toUTCString

replacer

As the replacer parameter of JSON.serialize.

space

As the space parameter of JSON.serialize.

undef

For default NJSON.stringify serializes undefined values as well. If set to false, undefined values are treated as JSON.stringify does.

Compatibility

Requires Node.js v14.

The package is tested under all Node.js versions currently supported accordingly to Node.js Release.

TypeScript

TypeScript types are distributed with the package itself.

License

MIT License

Bugs

Do not hesitate to report any bug or inconsistency @github.

Donating

If you find useful this package, please consider the opportunity to donate some satoshis to this bitcoin address: 1Md9WFAHrXTb3yPBwQWmUfv2RmzrtbHioB