4 Commits

Author SHA1 Message Date
Zach Carter
cdd45ca8ad version 1.2.0 2011-06-12 13:42:05 -04:00
Zach Carter
348eeb4c11 Follow spec instead of rfc for top level strings/numbers/null/booleans 2011-06-12 13:40:39 -04:00
Zach Carter
acf3cd47bc Merge branch 'master' of github.com:zaach/jsonlint 2011-06-04 10:33:02 -04:00
Zach Carter
77766eeae9 Note command-line options in the readme 2011-06-01 16:09:35 -07:00
7 changed files with 48 additions and 43 deletions

View File

@@ -18,6 +18,19 @@ or pipe input into stdin:
jsonlint will either report a syntax error with details or pretty print the source if it is valid.
### Options
$ jsonlint -h
Usage: jsonlint <file> [options]
<file> file to parse; otherwise uses stdin
options:
-v, --version print version and exit
-s, --sort-keys sort object keys
-i, --in-place overwrite the file
-t CHAR, --indent CHAR character(s) to use for indentation
## Module interface
I'm not sure why you wouldn't use the built in `JSON.parse` but you can use jsonlint from a CommonJS module:

View File

@@ -2,9 +2,9 @@
var jsonlint = (function(){
var parser = {trace: function trace() { },
yy: {},
symbols_: {"error":2,"JSONString":3,"STRING":4,"JSONNumber":5,"NUMBER":6,"JSONNullLiteral":7,"NULL":8,"JSONBooleanLiteral":9,"TRUE":10,"FALSE":11,"JSONText":12,"JSONObject":13,"EOF":14,"JSONArray":15,"JSONValue":16,"{":17,"}":18,"JSONMemberList":19,"JSONMember":20,":":21,",":22,"[":23,"]":24,"JSONElementList":25,"$accept":0,"$end":1},
symbols_: {"error":2,"JSONString":3,"STRING":4,"JSONNumber":5,"NUMBER":6,"JSONNullLiteral":7,"NULL":8,"JSONBooleanLiteral":9,"TRUE":10,"FALSE":11,"JSONText":12,"JSONValue":13,"EOF":14,"JSONObject":15,"JSONArray":16,"{":17,"}":18,"JSONMemberList":19,"JSONMember":20,":":21,",":22,"[":23,"]":24,"JSONElementList":25,"$accept":0,"$end":1},
terminals_: {2:"error",4:"STRING",6:"NUMBER",8:"NULL",10:"TRUE",11:"FALSE",14:"EOF",17:"{",18:"}",21:":",22:",",23:"[",24:"]"},
productions_: [0,[3,1],[5,1],[7,1],[9,1],[9,1],[12,2],[12,2],[16,1],[16,1],[16,1],[16,1],[16,1],[16,1],[13,2],[13,3],[20,3],[19,1],[19,3],[15,2],[15,3],[25,1],[25,3]],
productions_: [0,[3,1],[5,1],[7,1],[9,1],[9,1],[12,2],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[15,2],[15,3],[20,3],[19,1],[19,3],[16,2],[16,3],[25,1],[25,3]],
performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
var $0 = $$.length - 1;
@@ -21,42 +21,28 @@ case 5:this.$ = false;
break;
case 6:return this.$ = $$[$0-1];
break;
case 7:return this.$ = $$[$0-1];
case 13:this.$ = {};
break;
case 8:this.$ = $$[$0];
case 14:this.$ = $$[$0-1];
break;
case 9:this.$ = $$[$0];
case 15:this.$ = [$$[$0-2], $$[$0]];
break;
case 10:this.$ = $$[$0];
case 16:this.$ = {}; this.$[$$[$0][0]] = $$[$0][1];
break;
case 11:this.$ = $$[$0];
case 17:this.$ = $$[$0-2]; $$[$0-2][$$[$0][0]] = $$[$0][1];
break;
case 12:this.$ = $$[$0];
case 18:this.$ = [];
break;
case 13:this.$ = $$[$0];
case 19:this.$ = $$[$0-1];
break;
case 14:this.$ = {};
case 20:this.$ = [$$[$0]];
break;
case 15:this.$ = $$[$0-1];
break;
case 16:this.$ = [$$[$0-2], $$[$0]];
break;
case 17:this.$ = {}; this.$[$$[$0][0]] = $$[$0][1];
break;
case 18:this.$ = $$[$0-2]; $$[$0-2][$$[$0][0]] = $$[$0][1];
break;
case 19:this.$ = [];
break;
case 20:this.$ = $$[$0-1];
break;
case 21:this.$ = [$$[$0]];
break;
case 22:this.$ = $$[$0-2]; $$[$0-2].push($$[$0]);
case 21:this.$ = $$[$0-2]; $$[$0-2].push($$[$0]);
break;
}
},
table: [{12:1,13:2,15:3,17:[1,4],23:[1,5]},{1:[3]},{14:[1,6]},{14:[1,7]},{3:11,4:[1,12],18:[1,8],19:9,20:10},{3:18,4:[1,12],5:19,6:[1,25],7:16,8:[1,22],9:17,10:[1,23],11:[1,24],13:20,15:21,16:15,17:[1,4],23:[1,5],24:[1,13],25:14},{1:[2,6]},{1:[2,7]},{14:[2,14],18:[2,14],22:[2,14],24:[2,14]},{18:[1,26],22:[1,27]},{18:[2,17],22:[2,17]},{21:[1,28]},{18:[2,1],21:[2,1],22:[2,1],24:[2,1]},{14:[2,19],18:[2,19],22:[2,19],24:[2,19]},{22:[1,30],24:[1,29]},{22:[2,21],24:[2,21]},{18:[2,8],22:[2,8],24:[2,8]},{18:[2,9],22:[2,9],24:[2,9]},{18:[2,10],22:[2,10],24:[2,10]},{18:[2,11],22:[2,11],24:[2,11]},{18:[2,12],22:[2,12],24:[2,12]},{18:[2,13],22:[2,13],24:[2,13]},{18:[2,3],22:[2,3],24:[2,3]},{18:[2,4],22:[2,4],24:[2,4]},{18:[2,5],22:[2,5],24:[2,5]},{18:[2,2],22:[2,2],24:[2,2]},{14:[2,15],18:[2,15],22:[2,15],24:[2,15]},{3:11,4:[1,12],20:31},{3:18,4:[1,12],5:19,6:[1,25],7:16,8:[1,22],9:17,10:[1,23],11:[1,24],13:20,15:21,16:32,17:[1,4],23:[1,5]},{14:[2,20],18:[2,20],22:[2,20],24:[2,20]},{3:18,4:[1,12],5:19,6:[1,25],7:16,8:[1,22],9:17,10:[1,23],11:[1,24],13:20,15:21,16:33,17:[1,4],23:[1,5]},{18:[2,18],22:[2,18]},{18:[2,16],22:[2,16]},{22:[2,22],24:[2,22]}],
defaultActions: {6:[2,6],7:[2,7]},
table: [{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],12:1,13:2,15:7,16:8,17:[1,14],23:[1,15]},{1:[3]},{14:[1,16]},{14:[2,7],18:[2,7],22:[2,7],24:[2,7]},{14:[2,8],18:[2,8],22:[2,8],24:[2,8]},{14:[2,9],18:[2,9],22:[2,9],24:[2,9]},{14:[2,10],18:[2,10],22:[2,10],24:[2,10]},{14:[2,11],18:[2,11],22:[2,11],24:[2,11]},{14:[2,12],18:[2,12],22:[2,12],24:[2,12]},{14:[2,3],18:[2,3],22:[2,3],24:[2,3]},{14:[2,4],18:[2,4],22:[2,4],24:[2,4]},{14:[2,5],18:[2,5],22:[2,5],24:[2,5]},{14:[2,1],18:[2,1],21:[2,1],22:[2,1],24:[2,1]},{14:[2,2],18:[2,2],22:[2,2],24:[2,2]},{3:20,4:[1,12],18:[1,17],19:18,20:19},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:23,15:7,16:8,17:[1,14],23:[1,15],24:[1,21],25:22},{1:[2,6]},{14:[2,13],18:[2,13],22:[2,13],24:[2,13]},{18:[1,24],22:[1,25]},{18:[2,16],22:[2,16]},{21:[1,26]},{14:[2,18],18:[2,18],22:[2,18],24:[2,18]},{22:[1,28],24:[1,27]},{22:[2,20],24:[2,20]},{14:[2,14],18:[2,14],22:[2,14],24:[2,14]},{3:20,4:[1,12],20:29},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:30,15:7,16:8,17:[1,14],23:[1,15]},{14:[2,19],18:[2,19],22:[2,19],24:[2,19]},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:31,15:7,16:8,17:[1,14],23:[1,15]},{18:[2,17],22:[2,17]},{18:[2,15],22:[2,15]},{22:[2,21],24:[2,21]}],
defaultActions: {16:[2,6]},
parseError: function parseError(str, hash) {
throw new Error(str);
},

View File

@@ -8,7 +8,7 @@
"lint",
"jsonlint"
],
"version": "1.1.1",
"version": "1.2.0",
"preferGlobal": true,
"repository": {
"type": "git",

View File

@@ -1,5 +1,5 @@
/*
/*
ECMA-262 5th Edition, 15.12.1 The JSON Grammar.
Modified to forbid top level primitives.
*/
@@ -35,25 +35,17 @@ JSONBooleanLiteral
;
JSONText
: JSONObject EOF
{return $$ = $1;}
| JSONArray EOF
: JSONValue EOF
{return $$ = $1;}
;
JSONValue
: JSONNullLiteral
{$$ = $1;}
| JSONBooleanLiteral
{$$ = $1;}
| JSONString
{$$ = $1;}
| JSONNumber
{$$ = $1;}
| JSONObject
{$$ = $1;}
| JSONArray
{$$ = $1;}
;
JSONObject

View File

@@ -17,9 +17,24 @@ exports["test string with line break"] = function () {
assert["throws"](function () {parser.parse(json)}, "should throw error");
};
exports["test a json payload should be an object or array not a string"] = function () {
var json = fs.readFileSync(__dirname + "/fails/1.json").toString();
assert["throws"](function () {parser.parse(json)}, "should throw error");
exports["test string literal"] = function () {
var json = '"foo"';
assert.equal(parser.parse(json), "foo");
};
exports["test number literal"] = function () {
var json = '1234';
assert.equal(parser.parse(json), 1234);
};
exports["test null literal"] = function () {
var json = '1234';
assert.equal(parser.parse(json), 1234);
};
exports["test boolean literal"] = function () {
var json = 'true';
assert.equal(parser.parse(json), true);
};
exports["test unclosed array"] = function () {

View File

@@ -1 +0,0 @@
"A JSON payload should be an object or array, not a string."

File diff suppressed because one or more lines are too long