Package detail

@brillout/json-serializer

brillout181.5kMIT0.5.15

Same as JSON but with added support for Date, undefined, Map, Set, and more.

readme

@brillout/json-serializer

Same as JSON but with added support for:

  • Date
  • undefined
  • Set
  • Map
  • BigInt
  • RegExp
  • NaN
  • Infinity

JSON is a good serializer for JavaScript values but is lacking some JavaScript types such as Date:

!INLINE /examples/date_json.js --hide-source-path

Whereas with @brillout/json-serializer:

!INLINE /examples/date_json-serializer.js --hide-source-path


Contents


Usage

!INLINE /examples/simple.js --hide-source-path


Full Example

Example exposing all differences between JSON and @brillout/json-serializer.

!INLINE /examples/json-serializer.js

To run the example:

$ git clone git@github.com:brillout/json-serializer
$ cd json-serializer
$ npm install
$ npm run self-link
$ node ./examples/json-serializer.js

The npm run self-link is required to be able to self require('@brillout/json-serializer').


How it Works

Let's see how @brillout/json-serializer serializes an object:

!INLINE /examples/inspect.js

@brillout/json-serializer is based on JSON while using prefixed strings for unsupported types.

@brillout/json-serializer uses the native JSON.parse and JSON.stringify functions while modifying the serialization of unsupported types.

changelog

0.5.15 (2024-12-09)

Bug Fixes

  • workaround unexpected Node.js condition resolving (fix vikejs/vike#2016) (f0caec5)

0.5.14 (2024-12-09)

Bug Fixes

0.5.13 (2024-07-10)

Bug Fixes

0.5.12 (2024-07-10)

Bug Fixes

  • improve messageCore type (0bcf56e)
  • pass more usefull pathString value (eb063d6)

Features

  • add subjectName to serialization error object (7220453)

0.5.11 (2024-07-10)

Bug Fixes

  • stop passing pathString to user-land replacer (3d4fd16)

Features

  • add more information to serializatoin error object (d173e8a)

BREAKING CHANGES

  • replacer() doesn't recevied the pathString argument anymore: ```diff stringify(something, {
  • replacer(key, val, pathString) {
  • replacer(key, val) { // ... } } ```

0.5.10 (2024-05-02)

Features

  • expose parseTransform() (481e63c)

0.5.9 (2024-05-02)

Features

0.5.8 (2023-11-02)

Bug Fixes

0.5.7 (2023-11-02)

Features

0.5.6 (2023-09-03)

Bug Fixes

  • make error messages prettier (313bb24)
  • make error messages prettier (a448408)
  • make error messages prettier (e4b5781)
  • make paths prettier (1d04319)
  • object value path in error messages (5d9f0dd)

Features

  • make error message core available at err.messageCore (3d08d57)

0.5.5 (2023-08-26)

Bug Fixes

  • add License to package.json (b3ef4c4)

0.5.4 (2023-07-15)

Bug Fixes

  • improve serialization error message (19a18ca)

0.5.3 (2022-11-03)

Bug Fixes

  • add index.mjs to npm package (#9) (df5b103)

0.5.2 (2022-11-03)

Bug Fixes

  • workaround Vite SSR externalizing bug (a26b069)

0.5.1 (2022-09-03)

Bug Fixes

0.5.0 (2022-09-02)

  • perf!: forbid loading both parse() and stringify() at the same time (8365764)

Features

  • new option sortObjectKeys for stable hashing (6579f21)

BREAKING CHANGES

  • Module @brillout/json-serializer doesn't exist anymore: load @brillout/json-serializer/parse and @brillout/json-serializer/stringify instead. (To reduce loaded KBs on the browser-side.)