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

json3

v3.3.3

Published

A JSON polyfill for older JavaScript platforms.

Downloads

10,867,061

Readme

🚨 Unmaintained 🚨

Thanks to everyone who contributed patches or found it useful! ❤️

JSON 3

No Maintenance Intended

JSON 3 was a JSON polyfill for older JavaScript platforms.

About

JSON is a language-independent data interchange format based on a loose subset of the JavaScript grammar. Originally popularized by Douglas Crockford, the format was standardized in the fifth edition of the ECMAScript specification. The 5.1 edition, ratified in June 2011, incorporates several modifications to the grammar pertaining to the serialization of dates.

JSON 3 exposes two functions: stringify() for serializing a JavaScript value to JSON, and parse() for producing a JavaScript value from a JSON source string. The JSON 3 parser uses recursive descent instead of eval and regular expressions, which makes it slower on older platforms compared to JSON 2. The functions behave exactly as described in the ECMAScript spec, except for the date serialization discrepancy noted below.

The project is hosted on GitHub, along with the unit tests. It is part of the BestieJS family, a collection of best-in-class JavaScript libraries that promote cross-platform support, specification precedents, unit testing, and plenty of documentation.

Date Serialization

JSON 3 deviates from the specification in one important way: it does not define Date#toISOString() or Date#toJSON(). This preserves CommonJS compatibility and avoids polluting native prototypes. Instead, date serialization is performed internally by the stringify() implementation: if a date object does not define a custom toJSON() method, it is serialized as a simplified ISO 8601 date-time string.

Several native Date#toJSON() implementations produce date time strings that do not conform to the grammar outlined in the spec. In these environments, JSON 3 will override the native stringify() implementation. There is an issue on file to make these tests less strict.

Portions of the date serialization code are adapted from the date-shim project.

Usage

Web Browsers

<script src="//cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js"></script>
<script>
  JSON.stringify({"Hello": 123});
  // => '{"Hello":123}'
  JSON.parse("[[1, 2, 3], 1, 2, 3, 4]", function (key, value) {
    if (typeof value == "number") {
      value = value % 2 ? "Odd" : "Even";
    }
    return value;
  });
  // => [["Odd", "Even", "Odd"], "Odd", "Even", "Odd", "Even"]
</script>

When used in a web browser, JSON 3 exposes an additional JSON3 object containing the noConflict() and runInContext() functions, as well as aliases to the stringify() and parse() functions.

noConflict and runInContext

  • JSON3.noConflict() restores the original value of the global JSON object and returns a reference to the JSON3 object.
  • JSON3.runInContext([context, exports]) initializes JSON 3 using the given context object (e.g., window, global, etc.), or the global object if omitted. If an exports object is specified, the stringify(), parse(), and runInContext() functions will be attached to it instead of a new object.

Asynchronous Module Loaders

JSON 3 is defined as an anonymous module for compatibility with RequireJS, curl.js, and other asynchronous module loaders.

<script src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.js"></script>
<script>
  require({
    "paths": {
      "json3": "./path/to/json3"
    }
  }, ["json3"], function (JSON) {
    JSON.parse("[1, 2, 3]");
    // => [1, 2, 3]
  });
</script>

To avoid issues with third-party scripts, JSON 3 is exported to the global scope even when used with a module loader. If this behavior is undesired, JSON3.noConflict() can be used to restore the global JSON object to its original value.

Note: If you intend to use JSON3 alongside another module, please do not simply concatenate these modules together, as that would cause multiple define calls in one script, resulting in errors in AMD loaders. The r.js build optimizer can be used instead if you need a single compressed file for production.

CommonJS Environments

var JSON3 = require("./path/to/json3");
JSON3.parse("[1, 2, 3]");
// => [1, 2, 3]

JavaScript Engines

load("path/to/json3.js");
JSON.stringify({"Hello": 123, "Good-bye": 456}, ["Hello"], "\t");
// => '{\n\t"Hello": 123\n}'

Compatibility

JSON 3 has been tested with the following web browsers, CommonJS environments, and JavaScript engines.

Web Browsers

CommonJS Environments

JavaScript Engines

Known Incompatibilities

  • Attempting to serialize the arguments object may produce inconsistent results across environments due to specification version differences. As a workaround, please convert the arguments object to an array first: JSON.stringify([].slice.call(arguments, 0)).

Required Native Methods

JSON 3 assumes that the following methods exist and function as described in the ECMAScript specification:

  • The Number, String, Array, Object, Date, SyntaxError, and TypeError constructors.
  • String.fromCharCode
  • Object#toString
  • Object#hasOwnProperty
  • Function#call
  • Math.floor
  • Number#toString
  • Date#valueOf
  • String.prototype: indexOf, charCodeAt, charAt, slice, replace.
  • Array.prototype: push, pop, join.