json-strictify alternatives and similar modules
Based on the "Miscellaneous" category.
Alternatively, view json-strictify alternatives based on common mentions on social networks and blogs.
-
Electron
:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS -
cheerio
The fast, flexible, and elegant library for parsing and manipulating HTML and XML. -
jsdom
A JavaScript implementation of various web standards, for use with Node.js -
v86
x86 virtualization in your browser, recompiling x86 to wasm on the fly -
dotenv
Loads environment variables from .env for nodejs projects. -
patch-package
Fix broken node modules instantly ๐๐ฝโโ๏ธ๐จ -
ssh2
SSH2 client and server modules written in pure JavaScript for node.js -
hypernova
A service for server-side rendering your JavaScript views -
file-type
Detect the file type of a Buffer/Uint8Array/ArrayBuffer -
webworker-threads
Lightweight Web Worker API implementation with native threads -
node-pre-gyp
Node.js tool for easy binary deployment of C++ addons -
Bottleneck
Job scheduler and rate limiter, supports Clustering -
mem
Memoize functions - an optimization technique used to speed up consecutive function calls by caching the result of calls with identical input -
hasha
Hashing made simple. Get the hash of a buffer/string/stream/file. -
dot-prop
Get, set, or delete a property from a nested object using a dot path -
node-bell
Real-time anomalies detection for periodic time series. -
basic-ftp
FTP client for Node.js, supports FTPS over TLS, passive mode over IPv6, async/await, and Typescript. -
schemapack
Create a schema object to encode/decode your JSON in to a compact byte buffer with no overhead. -
nar
node.js application archive - create self-contained binary like executable applications that are ready to ship and run -
stringify-object
Stringify an object/array like JSON.stringify just without all the double-quotes -
cashify
๐ธ Lightweight currency conversion library, successor of money.js -
node-video-lib
Node.js Video Library / MP4 & FLV parser / MP4 builder / HLS muxer -
require-uncached
Import a module while bypassing the cache -
resolve-from
Resolve the path of a module like require.resolve() but from a given path
AWS Cloud-aware infrastructure-from-code toolbox [NEW]
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of json-strictify or a related project?
README
json-strictify
Safely serialize a value to JSON without unintended loss of data or going into an infinite loop due to circular references.
Why
The native JSON.stringify
function drops or silently modifies all values that are not supported by the JSON specification:
JSON.stringify({ a: 42, b: undefined });
// returns '{"a":42}'
JSON.parse(JSON.stringify(NaN));
// returns null
JSON.stringify([1, NaN, 3]);
// returns '[1,null,3]'
In many cases this is not the behaviour you want: relying on the serialization method to clean up your data is error prone and can lead to subtle bugs that are annoying to find. json-strictify helps you to easily avoid these issues with literally a single line of code.
Unlike json-stringify-safe
it does not attempt to "fix" its input but always bails out when it encounters something that would prevent it from being serialized properly.
Installation
Simply install via npm:
npm install json-strictify
Usage
json-strictify exposes three methods: stringify
, parse
and enable
, so it can be used as a drop-in replacement for the native JSON object:
import JSON from 'json-strictify';
JSON.stringify(someObject);
The parse
method is simply a reference to the native JSON.parse
function.
Examples
The stringify
function throws an error if the input to be serialized contains invalid values:
import JSONs from 'json-strictify';
JSONs.stringify({ x: 42, y: NaN });
// InvalidValueError: Invalid value at /y (NaN is not JSON-serializable)
Also, if the data you want to stringify contains circular references a CircularReferenceError
is thrown:
const data = [];
data.push(data);
JSONs.stringify(data);
// CircularReferenceError: Circular reference found at "/0"
The location of the value that caused the error is given as a JSON Pointer reference.
ESLint integration
If you want to ensure that all serialization is done through json-strictify you can disable the global JSON
variable like so:
"globals": {
"JSON": "off"
}
See the ESLint documentation on configuring globals for details.
Disabling json-strictify
In production you may not want to have the additional overhead introduced by json-strictify. This can easily be avoided by calling the enabled
method:
import JSONs from 'json-strictify';
const JSON = JSONs.enabled(config.debug);
// or for older versions of Javascript:
const JSON = require('json-strictify').enabled(config.debug);
If called with a falsy parameter, enabled
will return an object that delegates directly to the native JSON object so there will be no performance penalty whatsoever.
Note: json-strictify is disabled by default if NODE_ENV
is set to production
(you may still enable it manually, of course).
*Note that all licence references and agreements mentioned in the json-strictify README section above
are relevant to that project's source code only.