JSON for the ES5 era.

npm install json5
1 047 downloads in the last day
5 779 downloads in the last week
13 483 downloads in the last month

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.

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.

JSON5 aims to do for JSON what ES5 and HTML5 did for JavaScript and HTML. It also aims to continue being a subset of regular JavaScript — ES5 flavor.


This project is a WIP, so these aren't necessarily all implemented yet, but these are the goals:

  • Object keys don't need to be quoted if they contain no special characters. Yes, even reserved keywords are valid unquoted keys in ES5.

  • Strings can be single-quoted.

  • Strings can be multi-line; just prefix the newline with a backslash.

  • Objects and arrays can have trailing commas.

  • Both inline (single-line) and block (multi-line) comments are allowed.

  • [TODO] Octal and hexadecimal numbers are allowed. [Is this a bad idea?]


    foo: 'bar',
    while: true,

    this: 'is a\
 multi-line string',

    // this is an inline comment
    here: 'is another', // inline comment

    /* this is a block comment
       it continues on another line */

    finally: 'a trailing comma',
    oh: [
        'we shouldn\'t forget',
        'arrays can have',
        'trailing commas too',


MIT License. © 2012 Aseem Kishore.


Michael Bolin independently arrived at and published some of these same ideas with awesome explanations and detail. Recommended reading: Suggested Improvements to JSON

Douglas Crockford of course designed and built JSON, but his state machine diagrams on the JSON website, 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 json_parse.js parser. I'm super grateful for that clean and well-documented code.

npm loves you