Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-expressible

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-expressible

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

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

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));

Keywords

FAQs

Package last updated on 18 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc