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

JSON2016

v1.0.0

Published

A modern refresh of JSON with additions for trailing commas, dates, and comments.

Downloads

25

Readme

JSON2016

Purpose

JSON2016 is a polyfill for modernized update to JSON. It adds support to JSON in javascript for trailing commas, dates, and comments. Nothing else is changed for the original json specification.

Installation

npm install JSON2016

Usage

JSON2016 has three usage aproaches, depending on your environment: Node, Browser, or Browserify.

NodeJS Usage

JSON2016 can be required just like any other node module:

var json = require("JSON2016");
json.parse(...);
json.stringify(...);

JSON2016 can also be "installed" which will essentially replace the global JSON object with the JSON2016 version.

require("JSON2016").install();
JSON.parse(...);
JSON.stringify(...);

Browser Usage

JSON2016 can be directly included into your browser scripts:

	<script src="./JSON2016.js"></script>

JSON2016 can also be "installed" which will essentially replace the global JSON object with the JSON2016 version.

	<script>
		var f = function() {
			if (window && window.JSON2016) {
				window.JSON2016.install();
			}
			else {
				setTimeout(f,100);
			}
		};
		f();
	</script>

Browserify Usage

JSON2016 can be used with browserify and it has no underlying dependencies. Just require it in your source and browserify will handle the rest. Nothing special.

var json = require("JSON2016");
json.parse(...);
json.stringify(...);

JSON2016 can also be "installed" which will essentially replace the global JSON object with the JSON2016 version.

require("JSON2016").install();
JSON.parse(...);
JSON.stringify(...);

JSON Changes

JSON2016 adds three new rules to the JSON standard...

Comments

JSON20167 allow for commas to occur inside of JSON. JSON2016 will remove the comments prior to JSON parsing.

Comments may be of the following forms:

    // start of json
 	{
 		// comment at the start of an object literal
 		// and it can be multi-line.

 		"one": 1, 		// comment after a value
 		"two": 2 		// works regardless of comma or tabs/space/newlines

 		// comment at the end of an object literal
    }
    // end of json

Trailing Commas

JSON2016 will fix any trailing commas, empty commas, or the like.

NOTE: There is one side effect for trailing comma filtering in that if you have multiple commas bunched together in your json string, JSON2016 will convert them to a single comma.

 	{
 		"one": 1,
 		"two": 1,,,,,,
 	}

Dates

JSON20165 will encode and decode dates into a special format so that JSON2016 can recognize them as dates.

NOTE: JSON2016 Dates are incompatible with standard JSON, so don't expect them to parse if you use a standard JSON parser.

Any date run through stringify() will be returned in the form d1234567 where "d" signifies it is a date, and the number following is the date as a valid UTC based epoch long.

JSON parsed using JSON2016 can recognize the d1234567 format and will convert it to an appropriate JavaScript Date object.

Example JSON2016

{
	// comment
	"integer": 1,
	"float": 2.2,
	"boolean:" false,
	"string": "the quick brown fox jumped over the lazy dog.",
	"date": d1234567890123,
	"array": [],
	"object": {},
	// notice the trailing comma
}

Known Side Effects

  • Multiple commas in valid strings will be reduced to a single comma.

  • Anything of the form "~D#~D~\d+~" (ie "~D#~D~12345~") as its own String will be treated as a date. This is pretty rare.

Performance

This relies on regular expression parsing of incoming json strings. It is thus not unreasonable to expect a minor performance hit when using JSON2016. Maybe some day we can get these change incorporated into the underlying architecture and this polyfill will no longer be necessary. However, until then, JSON2016 will cost extra.

Feedback

Feedback on this tool is always welcome and bugs submitted via github will always be answered.

Thanks for using JSON2016.