Skip to content

Commit

Permalink
Created gh-pages branch via GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
aseemk committed May 29, 2012
0 parents commit 0307770
Show file tree
Hide file tree
Showing 5 changed files with 520 additions and 0 deletions.
178 changes: 178 additions & 0 deletions index.html
@@ -0,0 +1,178 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>JSON5 by aseemk</title>

<link rel="stylesheet" href="stylesheets/styles.css">
<link rel="stylesheet" href="stylesheets/pygment_trac.css">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="wrapper">
<header>
<h1>JSON5</h1>
<p>JSON for the ES5 generation.</p>
<p class="view"><a href="https://github.com/aseemk/json5">View the Project on GitHub <small>aseemk/json5</small></a></p>
<ul>
<li><a href="https://github.com/aseemk/json5/zipball/master">Download <strong>ZIP File</strong></a></li>
<li><a href="https://github.com/aseemk/json5/tarball/master">Download <strong>TAR Ball</strong></a></li>
<li><a href="https://github.com/aseemk/json5">View On <strong>GitHub</strong></a></li>
</ul>
</header>
<section>
<p>JSON isn't the friendliest to write and maintain by hand. Keys need to be
quoted; objects and arrays can't have trailing commas; comments aren't
supported — even though none of these is the case with regular JavaScript
today.</p>

<p>Restricting JSON to such a strict subset of "JavaScript object notation" made
sense for making it a great data-exchange format, but JSON's usage has
expanded <a href="http://plovr.com/docs.html">beyond</a> <a href="http://npmjs.org/doc/json.html">machine-to-machine</a> <a href="http://code.google.com/p/fuzztester/wiki/JSONFileFormat">communication</a>.</p>

<p><strong>JSON5 is a proposed extension to JSON</strong> that brings ES5 enhancements to its
syntax. It remains a <strong>strict subset of JavaScript</strong>, adds <strong>no new data
types</strong>, and is a <strong>strict superset of existing JSON</strong>.</p>

<p>JSON5 is not an official successor to JSON, and existing JSON parsers may not
understand these new features. It's thus recommended that files use a new
extension like <code>.json5</code> to be explicit. <em>[TODO: New MIME type too?]</em></p>

<p>This module provides a JavaScript implementation that works on all modern JS
engines (even IE6). Its parser is based directly off of Douglas Crockford's
eval-free <a href="https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js">json_parse.js</a>, making it both secure and robust. Give it a try!</p>

<h2>Features</h2>

<p>These are the new features of JSON5's syntax. All of these are optional, and
all of these are part of ES5 JavaScript.</p>

<ul>
<li>
<p>Object keys don't need to be quoted if they contain no <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Core_Language_Features#Variables">special characters</a>. Yes, even reserved keywords are valid keys in ES5 [<a href="http://es5.github.com/#x11.1.5">§11.1.5</a>, <a href="http://es5.github.com/#x7.6">§7.6</a>].</p>

<p><em>[TODO: Unicode characters and escape sequences aren't yet supported in this implementation.]</em></p>
</li>
<li><p>Strings can be single-quoted.</p></li>
<li><p>Strings can be split across multiple lines; just prefix each newline with a
backslash. [ES5 <a href="http://es5.github.com/#x7.8.4">§7.8.4</a>]</p></li>
<li><p>Objects and arrays can have trailing commas.</p></li>
<li><p>Both inline (single-line) and block (multi-line) comments are allowed.</p></li>
</ul><h2>Example</h2>

<div class="highlight">
<pre><span class="p">{</span>
<span class="nx">foo</span><span class="o">:</span> <span class="s1">'bar'</span><span class="p">,</span>
<span class="k">while</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span>

<span class="k">this</span><span class="o">:</span> <span class="s1">'is a\</span>
<span class="s1"> multi-line string'</span><span class="p">,</span>

<span class="c1">// this is an inline comment</span>
<span class="nx">here</span><span class="o">:</span> <span class="s1">'is another'</span><span class="p">,</span> <span class="c1">// inline comment</span>

<span class="cm">/* this is a block comment</span>
<span class="cm"> that continues on another line */</span>

<span class="k">finally</span><span class="o">:</span> <span class="s1">'a trailing comma'</span><span class="p">,</span>
<span class="nx">oh</span><span class="o">:</span> <span class="p">[</span>
<span class="s2">"we shouldn't forget"</span><span class="p">,</span>
<span class="s1">'arrays can have'</span><span class="p">,</span>
<span class="s1">'trailing commas too'</span><span class="p">,</span>
<span class="p">],</span>
<span class="p">}</span>
</pre>
</div>


<h2>Installation</h2>

<p>Via npm on Node:</p>

<pre><code>npm install json5
</code></pre>

<div class="highlight">
<pre><span class="kd">var</span> <span class="nx">JSON5</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'json5'</span><span class="p">);</span>
</pre>
</div>


<p>Or in the browser (adds the <code>JSON5</code> object to the global namespace):</p>

<div class="highlight">
<pre><span class="nt">&lt;script </span><span class="na">src=</span><span class="s">"json5.js"</span><span class="nt">&gt;&lt;/script&gt;</span>
</pre>
</div>


<h2>Usage</h2>

<div class="highlight">
<pre><span class="kd">var</span> <span class="nx">obj</span> <span class="o">=</span> <span class="nx">JSON5</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="s1">'{unquoted:"key",trailing:"comma",}'</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">str</span> <span class="o">=</span> <span class="nx">JSON5</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">obj</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">obj</span><span class="p">);</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">str</span><span class="p">);</span>
</pre>
</div>


<p><code>JSON5.stringify()</code> is currently aliased to the native <code>JSON.stringify()</code> in
order for the output to be fully compatible with all JSON parsers today.</p>

<h2>Development</h2>

<pre><code>git clone git://github.com/aseemk/json5.git
cd json5
npm install
npm test
</code></pre>

<p>Feel free to <a href="https://github.com/aseemk/json5/issues">file issues</a> and submit
<a href="https://github.com/aseemk/json5/pulls">pull requests</a> — contributions are
welcome.</p>

<p>If you submit a pull request, please be sure to add or update corresponding
test cases, and ensure that <code>npm test</code> continues to pass.</p>

<h2>License</h2>

<p>MIT License. © 2012 Aseem Kishore.</p>

<h2>Credits</h2>

<p><a href="http://bolinfest.com/">Michael Bolin</a> independently arrived at and published
some of these same ideas with awesome explanations and detail.
Recommended reading:
<a href="http://bolinfest.com/essays/json.html">Suggested Improvements to JSON</a></p>

<p><a href="http://www.crockford.com/">Douglas Crockford</a> of course designed and built
JSON, but his state machine diagrams on the <a href="http://json.org/">JSON website</a>,
as cheesy as it may sound, gave me motivation and confidence that building a
new parser to implement these ideas this was within my reach!
This code is also modeled directly off of Doug's open-source <a href="https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js">json_parse.js</a>
parser. I'm super grateful for that clean and well-documented code.</p>
</section>
<footer>
<p>This project is maintained by <a href="https://github.com/aseemk">aseemk</a></p>
<p><small>Hosted on GitHub Pages &mdash; Theme by <a href="https://github.com/orderedlist">orderedlist</a></small></p>
</footer>
</div>
<script src="javascripts/scale.fix.js"></script>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-32213209-1");
pageTracker._trackPageview();
} catch(err) {}
</script>

</body>
</html>
17 changes: 17 additions & 0 deletions javascripts/scale.fix.js
@@ -0,0 +1,17 @@
var metas = document.getElementsByTagName('meta');
var i;
if (navigator.userAgent.match(/iPhone/i)) {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
}
}
document.addEventListener("gesturestart", gestureStart, false);
}
function gestureStart() {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
}
}
}
1 change: 1 addition & 0 deletions params.json
@@ -0,0 +1 @@
{"name":"JSON5","body":"JSON isn't the friendliest to write and maintain by hand. Keys need to be\r\nquoted; objects and arrays can't have trailing commas; comments aren't\r\nsupported — even though none of these is the case with regular JavaScript\r\ntoday.\r\n\r\nRestricting JSON to such a strict subset of \"JavaScript object notation\" made\r\nsense for making it a great data-exchange format, but JSON's usage has\r\nexpanded [beyond][ex1] [machine-to-machine][ex2] [communication][ex3].\r\n\r\n[ex1]: http://plovr.com/docs.html\r\n[ex2]: http://npmjs.org/doc/json.html\r\n[ex3]: http://code.google.com/p/fuzztester/wiki/JSONFileFormat\r\n\r\n**JSON5 is a proposed extension to JSON** that brings ES5 enhancements to its\r\nsyntax. It remains a **strict subset of JavaScript**, adds **no new data\r\ntypes**, and is a **strict superset of existing JSON**.\r\n\r\nJSON5 is not an official successor to JSON, and existing JSON parsers may not\r\nunderstand these new features. It's thus recommended that files use a new\r\nextension like `.json5` to be explicit. *[TODO: New MIME type too?]*\r\n\r\nThis module provides a JavaScript implementation that works on all modern JS\r\nengines (even IE6). Its parser is based directly off of Douglas Crockford's\r\neval-free [json_parse.js][], making it both secure and robust. Give it a try!\r\n\r\n## Features\r\n\r\nThese are the new features of JSON5's syntax. All of these are optional, and\r\nall of these are part of ES5 JavaScript.\r\n\r\n- Object keys don't need to be quoted if they contain no [special characters](\r\n https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Core_Language_Features#Variables). Yes, even reserved keywords are valid keys in ES5 [[§11.1.5](http://es5.github.com/#x11.1.5), [§7.6](http://es5.github.com/#x7.6)].\r\n\r\n *[TODO: Unicode characters and escape sequences aren't yet supported in this implementation.]*\r\n\r\n- Strings can be single-quoted.\r\n\r\n- Strings can be split across multiple lines; just prefix each newline with a\r\n backslash. [ES5 [§7.8.4](http://es5.github.com/#x7.8.4)]\r\n\r\n- Objects and arrays can have trailing commas.\r\n\r\n- Both inline (single-line) and block (multi-line) comments are allowed.\r\n\r\n## Example\r\n\r\n```js\r\n{\r\n foo: 'bar',\r\n while: true,\r\n \r\n this: 'is a\\\r\n multi-line string',\r\n \r\n // this is an inline comment\r\n here: 'is another', // inline comment\r\n \r\n /* this is a block comment\r\n that continues on another line */\r\n \r\n finally: 'a trailing comma',\r\n oh: [\r\n \"we shouldn't forget\",\r\n 'arrays can have',\r\n 'trailing commas too',\r\n ],\r\n}\r\n```\r\n\r\n## Installation\r\n\r\nVia npm on Node:\r\n\r\n```\r\nnpm install json5\r\n```\r\n\r\n```js\r\nvar JSON5 = require('json5');\r\n```\r\n\r\nOr in the browser (adds the `JSON5` object to the global namespace):\r\n\r\n```html\r\n<script src=\"json5.js\"></script>\r\n```\r\n\r\n## Usage\r\n\r\n```js\r\nvar obj = JSON5.parse('{unquoted:\"key\",trailing:\"comma\",}');\r\nvar str = JSON5.stringify(obj);\r\nconsole.log(obj);\r\nconsole.log(str);\r\n```\r\n\r\n`JSON5.stringify()` is currently aliased to the native `JSON.stringify()` in\r\norder for the output to be fully compatible with all JSON parsers today.\r\n\r\n## Development\r\n\r\n```\r\ngit clone git://github.com/aseemk/json5.git\r\ncd json5\r\nnpm install\r\nnpm test\r\n```\r\n\r\nFeel free to [file issues](https://github.com/aseemk/json5/issues) and submit\r\n[pull requests](https://github.com/aseemk/json5/pulls) — contributions are\r\nwelcome.\r\n\r\nIf you submit a pull request, please be sure to add or update corresponding\r\ntest cases, and ensure that `npm test` continues to pass.\r\n\r\n## License\r\n\r\nMIT License. © 2012 Aseem Kishore.\r\n\r\n## Credits\r\n\r\n[Michael Bolin](http://bolinfest.com/) independently arrived at and published\r\nsome of these same ideas with awesome explanations and detail.\r\nRecommended reading:\r\n[Suggested Improvements to JSON](http://bolinfest.com/essays/json.html)\r\n\r\n[Douglas Crockford](http://www.crockford.com/) of course designed and built\r\nJSON, but his state machine diagrams on the [JSON website](http://json.org/),\r\nas cheesy as it may sound, gave me motivation and confidence that building a\r\nnew parser to implement these ideas this was within my reach!\r\nThis code is also modeled directly off of Doug's open-source [json_parse.js][]\r\nparser. I'm super grateful for that clean and well-documented code.\r\n\r\n[json_parse.js]: https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js\r\n","tagline":"JSON for the ES5 generation.","google":"UA-32213209-1","note":"Don't delete this file! It's used internally to help with page regeneration."}
69 changes: 69 additions & 0 deletions stylesheets/pygment_trac.css
@@ -0,0 +1,69 @@
.highlight { background: #ffffff; }
.highlight .c { color: #999988; font-style: italic } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { font-weight: bold } /* Keyword */
.highlight .o { font-weight: bold } /* Operator */
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #999999 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold; } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { font-weight: bold } /* Keyword.Constant */
.highlight .kd { font-weight: bold } /* Keyword.Declaration */
.highlight .kn { font-weight: bold } /* Keyword.Namespace */
.highlight .kp { font-weight: bold } /* Keyword.Pseudo */
.highlight .kr { font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #009999 } /* Literal.Number */
.highlight .s { color: #d14 } /* Literal.String */
.highlight .na { color: #008080 } /* Name.Attribute */
.highlight .nb { color: #0086B3 } /* Name.Builtin */
.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */
.highlight .no { color: #008080 } /* Name.Constant */
.highlight .ni { color: #800080 } /* Name.Entity */
.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */
.highlight .nn { color: #555555 } /* Name.Namespace */
.highlight .nt { color: #000080 } /* Name.Tag */
.highlight .nv { color: #008080 } /* Name.Variable */
.highlight .ow { font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #009999 } /* Literal.Number.Float */
.highlight .mh { color: #009999 } /* Literal.Number.Hex */
.highlight .mi { color: #009999 } /* Literal.Number.Integer */
.highlight .mo { color: #009999 } /* Literal.Number.Oct */
.highlight .sb { color: #d14 } /* Literal.String.Backtick */
.highlight .sc { color: #d14 } /* Literal.String.Char */
.highlight .sd { color: #d14 } /* Literal.String.Doc */
.highlight .s2 { color: #d14 } /* Literal.String.Double */
.highlight .se { color: #d14 } /* Literal.String.Escape */
.highlight .sh { color: #d14 } /* Literal.String.Heredoc */
.highlight .si { color: #d14 } /* Literal.String.Interpol */
.highlight .sx { color: #d14 } /* Literal.String.Other */
.highlight .sr { color: #009926 } /* Literal.String.Regex */
.highlight .s1 { color: #d14 } /* Literal.String.Single */
.highlight .ss { color: #990073 } /* Literal.String.Symbol */
.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #008080 } /* Name.Variable.Class */
.highlight .vg { color: #008080 } /* Name.Variable.Global */
.highlight .vi { color: #008080 } /* Name.Variable.Instance */
.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */

.type-csharp .highlight .k { color: #0000FF }
.type-csharp .highlight .kt { color: #0000FF }
.type-csharp .highlight .nf { color: #000000; font-weight: normal }
.type-csharp .highlight .nc { color: #2B91AF }
.type-csharp .highlight .nn { color: #000000 }
.type-csharp .highlight .s { color: #A31515 }
.type-csharp .highlight .sc { color: #A31515 }

0 comments on commit 0307770

Please sign in to comment.