function jsonValue() {

        function jsonObject() {
            var o = {}, t = nexttoken;
            advance('{');
            if (nexttoken.id !== '}') {
                for (;;) {
                    if (nexttoken.id === '(end)') {
                        error("Missing '}' to match '{' from line {a}.",
                                nexttoken, t.line);
                    } else if (nexttoken.id === '}') {
                        warning("Unexpected comma.", token);
                        break;
                    } else if (nexttoken.id === ',') {
                        error("Unexpected comma.", nexttoken);
                    } else if (nexttoken.id !== '(string)') {
                        warning("Expected a string and instead saw {a}.",
                                nexttoken, nexttoken.value);
                    }
                    if (o[nexttoken.value] === true) {
                        warning("Duplicate key '{a}'.",
                                nexttoken, nexttoken.value);
                    } else if (nexttoken.value === '__proto__') {
                        warning("Stupid key '{a}'.",
                                nexttoken, nexttoken.value);
                    } else {
                        o[nexttoken.value] = true;
                    }
                    advance();
                    advance(':');
                    jsonValue();
                    if (nexttoken.id !== ',') {
                        break;
                    }
                    advance(',');
                }
            }
            advance('}');
        }

        function jsonArray() {
            var t = nexttoken;
            advance('[');
            if (nexttoken.id !== ']') {
                for (;;) {
                    if (nexttoken.id === '(end)') {
                        error("Missing ']' to match '[' from line {a}.",
                                nexttoken, t.line);
                    } else if (nexttoken.id === ']') {
                        warning("Unexpected comma.", token);
                        break;
                    } else if (nexttoken.id === ',') {
                        error("Unexpected comma.", nexttoken);
                    }
                    jsonValue();
                    if (nexttoken.id !== ',') {
                        break;
                    }
                    advance(',');
                }
            }
            advance(']');
        }

        switch (nexttoken.id) {
        case '{':
            jsonObject();
            break;
        case '[':
            jsonArray();
            break;
        case 'true':
        case 'false':
        case 'null':
        case '(number)':
        case '(string)':
            advance();
            break;
        case '-':
            advance('-');
            if (token.character !== nexttoken.from) {
                warning("Unexpected space after '-'.", token);
            }
            adjacent(token, nexttoken);
            advance('(number)');
            break;
        default:
            error("Expected a JSON value.", nexttoken);
        }
    }
function jsonValue() {

        function jsonObject() {
            var o = {}, t = nexttoken;
            advance('{');
            if (nexttoken.id !== '}') {
                for (;;) {
                    if (nexttoken.id === '(end)') {
                        error("Missing '}' to match '{' from line {a}.",
                                nexttoken, t.line);
                    } else if (nexttoken.id === '}') {
                        warning("Unexpected comma.", token);
                        break;
                    } else if (nexttoken.id === ',') {
                        error("Unexpected comma.", nexttoken);
                    } else if (nexttoken.id !== '(string)') {
                        warning("Expected a string and instead saw {a}.",
                                nexttoken, nexttoken.value);
                    }
                    if (o[nexttoken.value] === true) {
                        warning("Duplicate key '{a}'.",
                                nexttoken, nexttoken.value);
                    } else if (nexttoken.value === '__proto__') {
                        warning("Stupid key '{a}'.",
                                nexttoken, nexttoken.value);
                    } else {
                        o[nexttoken.value] = true;
                    }
                    advance();
                    advance(':');
                    jsonValue();
                    if (nexttoken.id !== ',') {
                        break;
                    }
                    advance(',');
                }
            }
            advance('}');
        }

        function jsonArray() {
            var t = nexttoken;
            advance('[');
            if (nexttoken.id !== ']') {
                for (;;) {
                    if (nexttoken.id === '(end)') {
                        error("Missing ']' to match '[' from line {a}.",
                                nexttoken, t.line);
                    } else if (nexttoken.id === ']') {
                        warning("Unexpected comma.", token);
                        break;
                    } else if (nexttoken.id === ',') {
                        error("Unexpected comma.", nexttoken);
                    }
                    jsonValue();
                    if (nexttoken.id !== ',') {
                        break;
                    }
                    advance(',');
                }
            }
            advance(']');
        }

        switch (nexttoken.id) {
        case '{':
            jsonObject();
            break;
        case '[':
            jsonArray();
            break;
        case 'true':
        case 'false':
        case 'null':
        case '(number)':
        case '(string)':
            advance();
            break;
        case '-':
            advance('-');
            if (token.character !== nexttoken.from) {
                warning("Unexpected space after '-'.", token);
            }
            adjacent(token, nexttoken);
            advance('(number)');
            break;
        default:
            error("Expected a JSON value.", nexttoken);
        }
    }
function jsonValue ( ) { function jsonObject ( ) { var o = { } , t = nexttoken ; advance ( '{' ) ; if ( nexttoken . id !== '}' ) { for ( ; ; ) { if ( nexttoken . id === '(end)' ) { error ( "Missing '}' to match '{' from line {a}." , nexttoken , t . line ) ; } else if ( nexttoken . id === '}' ) { warning ( "Unexpected comma." , token ) ; break ; } else if ( nexttoken . id === ',' ) { error ( "Unexpected comma." , nexttoken ) ; } else if ( nexttoken . id !== '(string)' ) { warning ( "Expected a string and instead saw {a}." , nexttoken , nexttoken . value ) ; } if ( o [ nexttoken . value ] === true ) { warning ( "Duplicate key '{a}'." , nexttoken , nexttoken . value ) ; } else if ( nexttoken . value === '__proto__' ) { warning ( "Stupid key '{a}'." , nexttoken , nexttoken . value ) ; } else { o [ nexttoken . value ] = true ; } advance ( ) ; advance ( ':' ) ; jsonValue ( ) ; if ( nexttoken . id !== ',' ) { break ; } advance ( ',' ) ; } } advance ( '}' ) ; } function jsonArray ( ) { var t = nexttoken ; advance ( '[' ) ; if ( nexttoken . id !== ']' ) { for ( ; ; ) { if ( nexttoken . id === '(end)' ) { error ( "Missing ']' to match '[' from line {a}." , nexttoken , t . line ) ; } else if ( nexttoken . id === ']' ) { warning ( "Unexpected comma." , token ) ; break ; } else if ( nexttoken . id === ',' ) { error ( "Unexpected comma." , nexttoken ) ; } jsonValue ( ) ; if ( nexttoken . id !== ',' ) { break ; } advance ( ',' ) ; } } advance ( ']' ) ; } switch ( nexttoken . id ) { case '{' : jsonObject ( ) ; break ; case '[' : jsonArray ( ) ; break ; case 'true' : case 'false' : case 'null' : case '(number)' : case '(string)' : advance ( ) ; break ; case '-' : advance ( '-' ) ; if ( token . character !== nexttoken . from ) { warning ( "Unexpected space after '-'." , token ) ; } adjacent ( token , nexttoken ) ; advance ( '(number)' ) ; break ; default : error ( "Expected a JSON value." , nexttoken ) ; } }
Parse JSON
Parse JSON