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

json3

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json3

A JSON polyfill for older JavaScript platforms.

  • 3.3.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.1M
decreased by-20.67%
Maintainers
2
Weekly downloads
 
Created

What is json3?

The json3 npm package is a modern JSON implementation that provides a robust and consistent API for parsing and stringifying JSON data. It is designed to be a drop-in replacement for the native JSON object, offering improved performance and better handling of edge cases.

What are json3's main functionalities?

Parsing JSON

This feature allows you to parse a JSON string into a JavaScript object. The code sample demonstrates how to use JSON3 to parse a JSON string.

const JSON3 = require('json3');
const jsonString = '{"name":"John", "age":30, "city":"New York"}';
const jsonObject = JSON3.parse(jsonString);
console.log(jsonObject);

Stringifying JSON

This feature allows you to convert a JavaScript object into a JSON string. The code sample demonstrates how to use JSON3 to stringify a JavaScript object.

const JSON3 = require('json3');
const jsonObject = { name: "John", age: 30, city: "New York" };
const jsonString = JSON3.stringify(jsonObject);
console.log(jsonString);

Custom Replacer Function

This feature allows you to use a custom replacer function when stringifying a JavaScript object. The code sample demonstrates how to exclude numbers from the JSON string.

const JSON3 = require('json3');
const jsonObject = { name: "John", age: 30, city: "New York" };
const jsonString = JSON3.stringify(jsonObject, (key, value) => {
  if (typeof value === 'number') {
    return undefined; // Exclude numbers
  }
  return value;
});
console.log(jsonString);

Custom Space Argument

This feature allows you to format the JSON string with a custom space argument for better readability. The code sample demonstrates how to use a space argument to format the JSON string with indentation.

const JSON3 = require('json3');
const jsonObject = { name: "John", age: 30, city: "New York" };
const jsonString = JSON3.stringify(jsonObject, null, 2);
console.log(jsonString);

Other packages similar to json3

Keywords

FAQs

Package last updated on 27 May 2019

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