0.3.1 • Published 12 years ago

json5-utils v0.3.1

Weekly downloads
7,028
License
-
Repository
github
Last release
12 years ago

This JSON5 version is a subset of ES5 language, specification is here:

http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf

This is a language that defines data structures only, so following notes/restrictions are applied:

  • Literals (NullLiteral, BooleanLiteral, NumericLiteral, StringLiteral) are allowed.
  • Compatibility syntax is not supported, which means octal literals are forbidden.
  • ArrayLiterals and allowed, but instead of AssignmentExpressions you can only use other allowed Literals, ArrayLiterals and ObjectLiterals. Elisions are currently not supported.
  • ObjectLiterals and allowed, but instead of AssignmentExpressions you can only use other allowed Literals, ArrayLiterals and ObjectLiterals. Setters and getters are forbidden.
  • All other primary expressions ("this", Identifier, Expression) are forbidden.
  • Two unary expressions ('-' and '+') allowed before NumericLiterals.
  • Any data that has a number type can be represented, including +0, -0, +Infinity, -Infinity and NaN.
  • "undefined" is forbidden, use null instead if applicable.
  • Comments and whitespace are defined according to spec. Two or more consecutive asterisks in multiline comments are allowed.

Main authority here is ES5 spec, so strict backward JSON compatibility is not guaranteed.

If you're unsure whether a behaviour of this library is a bug or not, you can run this test:

JSON5.parse(String(something))

Should always be equal to:

eval('(function(){"use strict"\nreturn ('+String(something)+'\n)\n})()')

If something meets all rules above. Parens and newlines in the example above are carefully placed so comments and another newlines will work properly, so don't look so impressed about that.

0.3.1

12 years ago

0.3.0

12 years ago

0.2.1

12 years ago

0.2.0

12 years ago

0.1.0

12 years ago