npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-expressible

v1.0.5

Published

Micro library that determines whether a value can be expressed as JSON.

Downloads

43

Readme

CI-CD

JSON-Expressible

An ES5 Javascript micro library that determines whether a value can be expressed as JSON.

  • Checks whether the value is a valid JSON type (string, number, boolean, null, object, or array).

  • Recursively checks whether object children and/or array elements are valid JSON types.

  • Checks whether there are any circular references.

The motivation for this library is twofold:

  1. The JSON.stringify() function does not throw an error when it encounters non-JSON values like undefined and NaN. Instead, it omits the values or converts them to null in the returned serialization. As a result, parsing the serialization does not return the original value.

  2. It can be useful to know whether a value is expressible in JSON without actually serializing it.

To install:

npm install json-expressible

To use:

var jsonExpressible = require("json-expressible");

// The following return true

console.log(jsonExpressible("abc"));
console.log(jsonExpressible(123));
console.log(jsonExpressible(true));
console.log(jsonExpressible(null));
console.log(jsonExpressible({ abc: "def" }));
console.log(jsonExpressible([1, 2, 3]));


// The following return false

console.log(jsonExpressible(undefined));
console.log(jsonExpressible(NaN));
console.log(jsonExpressible(function () {}));
console.log(jsonExpressible(new Date()));
console.log(jsonExpressible(Infinity));
console.log(jsonExpressible(/reg.ex/));

console.log(jsonExpressible([ undefined ]));
console.log(jsonExpressible({ abc: undefined }));

var circularObject = {};
circularObject.ref = circularObject;
console.log(jsonExpressible(circularObject));

var circularArray = [];
circularArray.push(circularArray);
console.log(jsonExpressible(circularArray));