Skip to content
Grant Carthew edited this page Aug 3, 2018 · 10 revisions

Perj JSON Serialization

Initially with version 1 of the perj logger the JavaScript objects were converted into JSON strings (serialized) by using the fast-safe-stringify module.

It was discovered soon after the initial version 1 release that the fast-safe-stringify module had some issues recursively parsing Vue.js objects. It was also made apparent that using the passThrough option was literally passing the object references though to the write function.

With these issues in mind a new module was created called notation-copy.

notation-copy Module

The notation-copy module is an internal module to the perj project. It offers major improvements in the parsing of JavaScript objects both in the Node.js and Browser environments.

The notation-copy module supports the following features:

  • Fast Object Parsing.
  • Supports the same API as Object.assign.
  • Deep copies JavaScript objects in preparation for JSON stringification.
  • Replaces circular references with the [Circular] string token.
  • Removes non-JSON related artifacts such as Functions.
  • Follows the JSON.stringify MDN reference documentation for JavaScript type support.

By passing an object into the notation-copy module the returned resulting object has no references to the original object and is void of non-JSON constructs.

The notation-copy module is used to copy objects passed into the perj log methods. These sanitized objects are then stringified with a simple JSON.stringify call to provide the logger output. If the passThrough option is used with a custom write function, the object passed into the custom write function is clear of circular references and non-JSON related artifacts.