Comparing version 0.0.1 to 0.1.0
@@ -1,19 +0,27 @@ | ||
{ "name": "json5" | ||
, "version": "0.0.1" | ||
, "description": "Modern JSON." | ||
, "keywords": ["json", "json5"] | ||
, "author": "Aseem Kishore <aseem.kishore@gmail.com>" | ||
, "main": "json5" | ||
, "dependencies": {} | ||
, "devDependencies": | ||
{ "mocha": "~1.0.3" | ||
} | ||
, "scripts": | ||
{ "test": "mocha --ui exports --reporter list" | ||
} | ||
, "homepage": "https://github.com/aseemk/json5" | ||
,"repository": | ||
{ "type" : "git" | ||
, "url" : "https://github.com/aseemk/json5.git" | ||
} | ||
} | ||
{ | ||
"name": "json5", | ||
"version": "0.1.0", | ||
"description": "JSON for the ES5 era.", | ||
"keywords": [ | ||
"json", | ||
"es5" | ||
], | ||
"author": "Aseem Kishore <aseem.kishore@gmail.com>", | ||
"contributors": [ | ||
"Max Nanasy <max.nanasy@gmail.com>" | ||
], | ||
"main": "lib/json5.js", | ||
"bin": "lib/cli.js", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"mocha": "~1.0.3" | ||
}, | ||
"scripts": { | ||
"test": "mocha --ui exports --reporter spec" | ||
}, | ||
"homepage": "http://json5.org/", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/aseemk/json5.git" | ||
} | ||
} |
# JSON5 – Modern JSON | ||
JSON is strict. Keys need to be quoted; strings can only be double-quoted; | ||
objects and arrays can't have trailing commas; and comments aren't allowed. | ||
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. | ||
Using such a strict subset of "JavaScript object notation" was likely for the | ||
best at the time, but with modern ECMAScript 5 engines like V8 in Chrome and | ||
Node, these limitations are cumbersome. | ||
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 [beyond][ex1] [machine-to-machine][ex2] [communication][ex3]. | ||
JSON5 does for JSON what ES5 did for ES3. It also is to regular ES5 what JSON | ||
was to ES3 — a pure subset. | ||
[ex1]: http://plovr.com/docs.html | ||
[ex2]: http://npmjs.org/doc/json.html | ||
[ex3]: http://code.google.com/p/fuzztester/wiki/JSONFileFormat | ||
This module provides a replacement for ES5's native `JSON.parse()` method that | ||
understands these additions. The parser is based directly off of Douglas | ||
Crockford's [json_parse.js][], which avoids `eval()` and validates input as it | ||
parses it, making it secure and safe to use today. | ||
**JSON5 is a proposed extension to JSON** that brings ES5 enhancements to its | ||
syntax. It remains a **strict subset of JavaScript**, adds **no new data | ||
types**, and is a **strict superset of existing JSON**. | ||
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 `.json5` to be explicit. *[TODO: New MIME type too?]* | ||
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 [json_parse.js][], making it both secure and robust. Give it a try! | ||
## Features | ||
- Object keys don't need to be quoted if they contain no special characters. | ||
Yes, even reserved keywords are valid unquoted keys in ES5. | ||
These are the new features of JSON5's syntax. All of these are optional, and | ||
all of these are part of ES5 JavaScript. | ||
*[TODO: Unicode characters and escape sequences aren't yet supported in | ||
unquoted keys.]* | ||
- Object keys don't need to be quoted if they're valid [identifiers]( | ||
https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Core_Language_Features#Variables). Yes, even reserved keywords are valid unquoted keys in ES5 [[§11.1.5](http://es5.github.com/#x11.1.5), [§7.6](http://es5.github.com/#x7.6)]. | ||
*[TODO: Unicode characters and escape sequences aren't yet supported in this implementation.]* | ||
- Strings can be single-quoted. | ||
- Strings can be multi-line; just prefix the newline with a backslash. | ||
- Strings can be split across multiple lines; just prefix each newline with a | ||
backslash. [ES5 [§7.8.4](http://es5.github.com/#x7.8.4)] | ||
@@ -34,3 +46,4 @@ - Objects and arrays can have trailing commas. | ||
- *[IDEA: Allow octal and hexadecimal numbers.]* | ||
- Numbers can be hexadecimal (base 16), and they can also begin with a leading | ||
decimal (e.g. `.5`). | ||
@@ -51,7 +64,10 @@ ## Example | ||
/* this is a block comment | ||
it continues on another line */ | ||
that continues on another line */ | ||
hex: 0xDEADbeef, | ||
half: .5, | ||
finally: 'a trailing comma', | ||
oh: [ | ||
'we shouldn\'t forget', | ||
"we shouldn't forget", | ||
'arrays can have', | ||
@@ -93,2 +109,18 @@ 'trailing commas too', | ||
If you're running Node, you can also register a JSON5 `require()` hook to let | ||
you `require()` `.json5` files just like you can `.json` files: | ||
```js | ||
require('json5/lib/require'); | ||
require('./path/to/foo'); // tries foo.json5 after foo.js, foo.json, etc. | ||
require('./path/to/bar.json5'); | ||
``` | ||
This module also provides a `json5` executable (requires Node) for converting | ||
JSON5 files to sibling JSON files: | ||
``` | ||
$ json5 -c path/to/foo.json5 # generates path/to/foo.json | ||
``` | ||
## Development | ||
@@ -99,6 +131,18 @@ | ||
cd json5 | ||
npm link | ||
make | ||
make test | ||
``` | ||
If your system doesn't have Make, this should work in place of `make [test]`: | ||
``` | ||
./lib/cli.js -c package.json5 | ||
npm install | ||
npm test | ||
``` | ||
Make is used to auto-generate the package.json file that npm requires from our | ||
package.json5 file. Just re-run `make` (or `./lib/cli.js -c package.json5`) on | ||
changes to package.json5. | ||
Feel free to [file issues](https://github.com/aseemk/json5/issues) and submit | ||
@@ -109,7 +153,8 @@ [pull requests](https://github.com/aseemk/json5/pulls) — contributions are | ||
If you submit a pull request, please be sure to add or update corresponding | ||
test cases, and ensure that `npm test` continues to pass. | ||
test cases, and ensure that `make test` (or `npm test`) continues to pass. | ||
## License | ||
MIT License. © 2012 Aseem Kishore. | ||
MIT License. © 2012 Aseem Kishore, and [others]( | ||
https://github.com/aseemk/json5/contributors). | ||
@@ -131,1 +176,4 @@ ## Credits | ||
[json_parse.js]: https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js | ||
[Max Nanasy](https://github.com/MaxNanasy) has been an early and prolific | ||
supporter, contributing multiple patches and ideas. Thanks Max! |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
34922
66
535
174
3