Code Monkey home page Code Monkey logo

json5's Introduction

JSON5 – JSON for Humans

Build Status Coverage Status

JSON5 is an extension to the popular JSON file format that aims to be easier to write and maintain by hand (e.g. for config files). It is not intended to be used for machine-to-machine communication. (Keep using JSON or other file formats for that. 🙂)

JSON5 was started in 2012, and as of 2022, now gets >65M downloads/week, ranks in the top 0.1% of the most depended-upon packages on npm, and has been adopted by major projects like Chromium, Next.js, Babel, Retool, WebStorm, and more. It's also natively supported on Apple platforms like MacOS and iOS.

Formally, the JSON5 Data Interchange Format is a superset of JSON (so valid JSON files will always be valid JSON5 files) that expands its syntax to include some productions from ECMAScript 5.1 (ES5). It's also a subset of ES5, so valid JSON5 files will always be valid ES5.*

This JavaScript library is a reference implementation for JSON5 parsing and serialization, and is directly used in many of the popular projects mentioned above (where e.g. extreme performance isn't necessary), but others have created many other libraries across many other platforms.

Summary of Features

The following ECMAScript 5.1 features, which are not supported in JSON, have been extended to JSON5.

Objects

  • Object keys may be an ECMAScript 5.1 IdentifierName.
  • Objects may have a single trailing comma.

Arrays

  • Arrays may have a single trailing comma.

Strings

  • Strings may be single quoted.
  • Strings may span multiple lines by escaping new line characters.
  • Strings may include character escapes.

Numbers

  • Numbers may be hexadecimal.
  • Numbers may have a leading or trailing decimal point.
  • Numbers may be IEEE 754 positive infinity, negative infinity, and NaN.
  • Numbers may begin with an explicit plus sign.

Comments

  • Single and multi-line comments are allowed.

White Space

  • Additional white space characters are allowed.

Example

Kitchen-sink example:

{
  // comments
  unquoted: 'and you can quote me on that',
  singleQuotes: 'I can use "double quotes" here',
  lineBreaks: "Look, Mom! \
No \\n's!",
  hexadecimal: 0xdecaf,
  leadingDecimalPoint: .8675309, andTrailing: 8675309.,
  positiveSign: +1,
  trailingComma: 'in objects', andIn: ['arrays',],
  "backwardsCompatible": "with JSON",
}

A more real-world example is this config file from the Chromium/Blink project.

Specification

For a detailed explanation of the JSON5 format, please read the official specification.

Installation and Usage

Node.js

npm install json5

CommonJS

const JSON5 = require('json5')

Modules

import JSON5 from 'json5'

Browsers

UMD

<!-- This will create a global `JSON5` variable. -->
<script src="https://unpkg.com/json5@2/dist/index.min.js"></script>

Modules

<script type="module">
  import JSON5 from 'https://unpkg.com/json5@2/dist/index.min.mjs'
</script>

API

The JSON5 API is compatible with the JSON API.

JSON5.parse()

Parses a JSON5 string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.

Syntax

JSON5.parse(text[, reviver])

Parameters

  • text: The string to parse as JSON5.
  • reviver: If a function, this prescribes how the value originally produced by parsing is transformed, before being returned.

Return value

The object corresponding to the given JSON5 text.

JSON5.stringify()

Converts a JavaScript value to a JSON5 string, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.

Syntax

JSON5.stringify(value[, replacer[, space]])
JSON5.stringify(value[, options])

Parameters

  • value: The value to convert to a JSON5 string.
  • replacer: A function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting/filtering the properties of the value object to be included in the JSON5 string. If this value is null or not provided, all properties of the object are included in the resulting JSON5 string.
  • space: A String or Number object that's used to insert white space into the output JSON5 string for readability purposes. If this is a Number, it indicates the number of space characters to use as white space; this number is capped at 10 (if it is greater, the value is just 10). Values less than 1 indicate that no space should be used. If this is a String, the string (or the first 10 characters of the string, if it's longer than that) is used as white space. If this parameter is not provided (or is null), no white space is used. If white space is used, trailing commas will be used in objects and arrays.
  • options: An object with the following properties:
    • replacer: Same as the replacer parameter.
    • space: Same as the space parameter.
    • quote: A String representing the quote character to use when serializing strings.

Return value

A JSON5 string representing the value.

Node.js require() JSON5 files

When using Node.js, you can require() JSON5 files by adding the following statement.

require('json5/lib/register')

Then you can load a JSON5 file with a Node.js require() statement. For example:

const config = require('./config.json5')

CLI

Since JSON is more widely used than JSON5, this package includes a CLI for converting JSON5 to JSON and for validating the syntax of JSON5 documents.

Installation

npm install --global json5

Usage

json5 [options] <file>

If <file> is not provided, then STDIN is used.

Options:

  • -s, --space: The number of spaces to indent or t for tabs
  • -o, --out-file [file]: Output to the specified file, otherwise STDOUT
  • -v, --validate: Validate JSON5 but do not output JSON
  • -V, --version: Output the version number
  • -h, --help: Output usage information

Contributing

Development

git clone https://github.com/json5/json5
cd json5
npm install

When contributing code, please write relevant tests and run npm test and npm run lint before submitting pull requests. Please use an editor that supports EditorConfig.

Issues

To report bugs or request features regarding the JSON5 data format, please submit an issue to the official specification repository.

Note that we will never add any features that make JSON5 incompatible with ES5; that compatibility is a fundamental premise of JSON5.*

To report bugs or request features regarding this JavaScript implementation of JSON5, please submit an issue to this repository.

Security Vulnerabilities and Disclosures

To report a security vulnerability, please follow the follow the guidelines described in our security policy.

ECMAScript Compatibility

While JSON5 aims to be fully compatible with ES5, there is one exception where both JSON and JSON5 are not. Both JSON and JSON5 allow unescaped line and paragraph separator characters (U+2028 and U+2029) in strings, however ES5 does not. A proposal to allow these characters in strings was adopted into ES2019, making JSON and JSON5 fully compatible with ES2019.

License

MIT. See LICENSE.md for details.

Credits

Aseem Kishore founded this project. He wrote a blog post about the journey and lessons learned 10 years in.

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 us motivation and confidence that building a new parser to implement these ideas was within reach! The original implementation of JSON5 was also modeled directly off of Doug’s open-source json_parse.js parser. We’re grateful for that clean and well-documented code.

Max Nanasy has been an early and prolific supporter, contributing multiple patches and ideas.

Andrew Eisenberg contributed the original stringify method.

Jordan Tucker has aligned JSON5 more closely with ES5, wrote the official JSON5 specification, completely rewrote the codebase from the ground up, and is actively maintaining this project.

json5's People

Contributors

amb26 avatar aseemk avatar bnjmnt4n avatar craigmichaelmartin avatar edwardbetts avatar geopic avatar ianloic avatar ichenlei avatar jordanbtucker avatar kasperp avatar kevinji avatar marvinhagemeister avatar maxnanasy avatar mkantor avatar nipunn1313 avatar obondarava avatar rhysd avatar rlidwka avatar rowanhill avatar vassudanagunta avatar xehpuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

json5's Issues

JSON5 use cases in existing projects

We all know here that JSON5 is a great format for all kinds of project configuration files or simply data annotation.

I think it would be interesting to look at existing, real-world projects that already use a custom-flavored JSON superset and would benefit from adopting JSON5.

I started a gist here: https://gist.github.com/4078082
Feel free to contribute!

Problem with [ [Object] ]

I noticed that

JSON5.parse("{ ValidationError: { title: [ [Object] ] } }");

Fails with following message:

SyntaxError {message: "Unexpected 'O'", at: 32, text: "{ ValidationError: { title: [ [Object] ] } }"} 

Hexadecimal floating point values

I know this is not part of ES5, but considering that multiline discussion, it might make sense to break compatibility with JS anyway - who is using eval() these days anyway?

Allowing hexadecimal floating point values in the form of [-]0xh.hhhp[+-]d (see printf(3), conversion specifier aA) would allow it to store and read floating point values without loss of precision. With the current approach to floating point numbers, floating point values internally always have to be converted to/from a decimal representation which always loses precision.

CLI feature: validation

Current the CLI only converts JSON5 files to JSON. It validates the file in the process, so why not just have an option to validate your JSON5 files to see if they have any errors?

better support for text blocks

I would like JSON5 to have better support for text blocks. Currently, JSON's only way of encoding blocks of text is to enclose them in double quotes. So, any double quotes in the text must be escaped. Also, any embedded newlines are retained.

YAML (yaml.org) allows blocks of arbitrary text, the only restriction being that it must be indented past the key. It also supports two forms of text blocks: ones which begin with a "|" retain all white space (including newlines and tabs), as is; ones which begin with a ">" convert all sequences of white space to single spaces.

Python (python.org) uses a sequence of three double quotes (""") to begin and end a text block. This pretty much resolves the problem of embedded quotes, as this sequence is very unlikely to appear in a normal text block.

Variations on this approach (eg, ""|...|"", ""<...>"") might allow JSON5 to handle white space in the ways that YAML does.

Support octal and/or hex numbers?

Seems like it would be useful, but octal numbers in particular might throw people off. I'm wondering if there's a good reason JSON doesn't support it. Not sure.

a big fat discussion about octal literals

There are two good ways to deal with them:

  1. ES3 way, or treat them as octals, which means:
  • \1 -> \u0001
  • \8 -> parse error (?)
  • 020 -> 16
  • 080 -> parse error (?)
  • 0o20 -> parse error
  1. ES8 way, or treat them as decimals, which means:
  • \1 -> 1
  • \8 -> 8
  • 020 -> 20
  • 080 -> 80
  • 0o20 -> 16

About strict mode:

Strict mode is not a complete solution, it is just an intermediate mode between es3 code and future ecmascript versions.

And frankly speaking, it failed. The idea was to have a simpler JS parser, but it ended up all JS engines having 2 parsers, and now there are discussions in es-discuss about how can we get "just one JavaScript" back.

But nevermind that. My point is: comparison with strict mode doesn't make any sense, we either look for b/w compatibility or look into the future, and strict mode is just an intermediate one.


What it is and how it is used:

Octal, or base-8 literals, are heavily used in unix programming. Most famous example are file permissions (which are octal based, i.e. you could read 0755 as -rwxr-xr-x):

mode = 0777 & (~process.umask());

(source: substack/node-mkdirp)

Javascript got them from C or something like that, they are rarely used in web. But when node.js came in, octal numbers started to be used a lot (see Brendan's post in es-discuss 2 years ago).

Another use-case is ANSI escape sequences, in unix manuals ESC is usually written as \033:

console.log('  \033[90mrendered \033[36m%s\033[0m', path);

(source: visionmedia/jade)


Why it was considered a bad thing:

Developers who are unfamiliar with language could mistake them for decimal numbers and use them for padding.

Unfortunately, I can't find a single example of such an error right now.

But there is a notable example in es-discuss where people use octals, but probably don't even know they do:

new Date(2014, 08, 05)
new Date(2014, 10, 12)

Here 08 is a decimal, but 05 is octal. But it has no real effect, because single digit numbers are the same in any base.


How ES7+ is going to solve this:

Future javascript versions will allow 0o777 syntax as a direct replacement for 0777. You can test it right now in Firefox console. Unfortunately, I don't know any replacements for inline octals in strings.

Octals aren't deprecated because people don't like them. They are deprecated, because there is a talk about replacing them with decimal numbers, so:

ES3: `0123` -> 83
ES6: `0123` -> parse error
ES8: `0123` -> 123

I use "ES8" loosely, but the idea stays the same.


Now the main question:

Do we stick with legacy ES3 semantics, or follow bleeding edge of ES standards? There is no legacy JSON5 code to worry about, so either choice looks like a valid one.

Node require() support

Just like you can require() JSON files, we should add a hook to let you require() JSON5 files.

Should whitespace after an escaped newline get stripped?

See issue #21, specifically @Midar's comment.

The spec seems to imply that only the newline should get stripped, e.g. "The SV of LineContinuation :: \ LineTerminatorSequence is the empty character sequence."

Firefox and Safari strip just the newline, while Chrome/Node (V8) strip all whitespace after the newline as well. Inconsistent. =/

Match JSON errors when appropriate

Per my comment in #19.

If JSON throws an error, JSON5 should throw the same error unless the behavior has been changed by new features of JSON5 over JSON.

We should probably compile a list of all known JSON errors and write tests.

Update Grammar: JSON5 does not use ECMAScript line terminators

As specified in the first paragraph describing JSON.parse:

JSON ... allows Unicode code points U+2028 and U+2029 to directly appear in JSONString literals without using an escape sequence.

ES5 does not allow those characters in strings unescaped, since it includes those characters in its LineTerminator production.

In order to be backward compatible with JSON, JSON5 must also support those characters in strings and therefore cannot reference any of ES5's productions that recursively reference LineTerminator or LineTerminatorSequence, namely Comment and StringLiteral. At least not without caveats.

For this reason, I have updated the Grammar to indicate that the LineTerminator and LineTerminatorSequence productions should be substituted with alternative versions defined therein.

The alternative was to recursively redefine the very long Comment and StringLiteral productions as JSON5 versions.

No changes to code are required.

npm test in windows

npm test doesn't work in Windows

Any instruction to run the tests manually in Windows?

BTW, npm link is not supported in Windows

Add NaN

In current JSON specification I miss a way of expressing positive and negative infinity. Not-a-number is nice to have too, but it is not so important, as it coerces to null (both are falsy). Could it be added here?

[Edited by @aseemk: we've added infinities; so updated this title to reflect that we should add NaN too.]

Node json5 binary

It'd be great to have a json5 binary to convert .json5 files to .json. This'd be equivalent to e.g. coffee -c.

Support for numeric literals as property names

ES5 supports numeric literals as property names in object literals. [ES5 §11.1.5]

This allows productions like:

{    1 : 'int',
    .2 : 'float',
    3. : 'trailing dec',
  4e-2 : 'exp',
  0x50 : 'hex' }

All property names are normalized to strings. So the above will result in:

{    '1' : 'int',
     '3' : 'trailing dec',
    '80' : 'hex',
   '0.2' : 'float',
  '0.04' : 'exp' }

Note that the definition of numeric literal precludes signed numbers and special IEEE 745 values, so the following productions are either errors or not treated as numeric values.

{        -1 : 'neg (error)',
         +1 : 'pos (error)',
   Infinity : 'inf (valid but parsed as identifier)',
  -Infinity : 'neg inf (error)',
        NaN : 'not a num (valid but parsed as identifier)' }

Are there plans to support the same syntax that ES5 does? I don't see floating points used as property names very often, but I can see decimal and hexadecimal integers being useful.

Npm package.json5

Since npm is one of the primary use cases for more human-friendly JSON, it'd be fitting if our own package.json was a .json5 file, and we compiled to the .json file that npm (currently) expects. This'd have to be a manual process unfortunately.

Single quotes handled incorrectly, incompatible to JS

Since I already have comments and the number extensions in my JSON parser, I got interested when I found out about JSON5. When I noticed that it supports ', this got me curious while implementing it: How differently is ' handled from " in JS? I tried this in node, and as you can clearly see, it's a mess:

> '\foo'
'\foo'
> '\e'
'e'
> '\\e'
'\\e'

So basically, it's not handled like double quotes - and it also has a bug: It's not possible to write a backslash followed by a a letter other than b, f, n, r or t. \u is handled like in double quotes:

> '\u'
'u'
> '\u123'
'u123'
> '\u0033'
'3'

So a backslash followed by a u is alos not possible.

So, now I looked into the implementation and it seems all it does is set a variable to the delimiter and then look until that delimiter comes again, unescaped, of course. So this clearly is not compatbile to JS!

Now the question is: Is the implementation wrong or the spec? Which one should I implement? The JS behaviour or the behaviour implemented in JSON5? It's either a bug in the doumentation or the implementation.

Allow leading comma and empty values in arrays

Edit: the original title of this case was to disallow these things, considered bugs. That was fixed, but now the conversation below asks to consider re-allowing them.

ES5 allows these:

[,]     // => [undefined]
[,null] // => [undefined, null]

But I don't think that's needed in JSON5. Let's keep it simple and closer to JSON here.

This implementation currently allows these (by design); let's fix.

behaviour for trailing commas in array

Under ES rules var a = [,,,,] is a five element array, each element being undefined. What would be the expected behaviour of allowing trailing commas in arrays in JSON5? Would it deviate from true ES behaviour and treat the trailing comma as "not actually there", or would it simply allow it and treat it as a new element marker, that element being undefined?

JSON5 is not a subset of YAML

A downside of JSON5 is that it is no longer a full subset of YAML. Both camps made adjustments to ensure this relationship. It would be a shame to loose it for future versions.

Comments are the most obvious issue. YAML uses the # comment marker common to shell scripting, where as JSON5 is using // an /* */. Obviously, JSON5 is using those b/c they are Javascript's comments too. But I am wondering how this difference might be reconciled.

Another potential issue is treatment of \ in single-quoted strings. In YAML, '\n' is the same as '' 'n', while "\n" is a newline. It seems it means a newline in both cases in JSON5.

Other than that I think things are compatible.

Do not throw on duplicate keys

According to the note at the bottom of ES5 §15.12.2 regarding JSON.parse:

In the case where there are duplicate name Strings within an object, lexically preceding values for the same key shall be overwritten.

JSON5 throws on duplicate keys because that's what Crockford's implementation does. However, the JSON standard, Node.js, and browsers do not throw on duplicate keys.

> JSON.parse('{"a": true, "a": false}')
{ a: false }

> JSON5.parse('{"a": true, "a": false}')
SyntaxError: Duplicate key "a"

I propose that JSON5 overwrite duplicate keys instead of throwing.

I believe that JSON5 should be completely backward compatible with JSON. Anything that JSON can parse, JSON5 should parse exactly the same. There are other examples where JSON5 is not backward compatible, which I will begin documenting. Perhaps the Wiki is a good place for that?

Support for Unicode and escape sequences in property names.

Are there any ideas on how to support Unicode and their escape sequences in identifiers? What are the options, and what are the pros and cons of those options?

It seems the biggest hurdle is that there is no standard way to determine what Unicode category a code point belongs to. For example, an identifier can start with $, _, or any character in the five Letter categories or in the Number, Letter category. That's 17196 different characters, all spread across the Unicode code point list.

Here are some ideas on perhaps how to solve this:

  • Require a dependency that provides support for testing Unicode categories.
  • Bake in support for it yourself. I've already done some prototyping and benchmarking.
  • Consume Unicode escape sequences and forego testing them against appropriate Unicode classes, willfully violating the ES5 spec.
  • Something very obvious I haven't thought of yet.

I think it's worth discussing the costs and benefits of implementing this support. What do you think?

Add support for negative ES5 tests

We only test with eval() currently, to ensure that we remain a subset of ES5. But we might explicitly not allow some features of ES5 (like trailing decimal points, see #9) in order to remain closer to JSON. So we should add some test plumbing for features that are valid ES5 but not valid JSON5 (and still valid JSON).

Non-finite values are being output as null

This, when parsed:

{
    Infinity: Infinity,
    PositiveInfinity: +Infinity,
    NegativeInfinity: -Infinity,
    NaN: NaN,
    PositiveNaN: +NaN,
    NegativeNaN: -NaN,
}

becomes this, when stringified:

{
    Infinity: null,
    PositiveInfinity: null,
    NegativeInfinity: null,
    NaN: null,
    PositiveNaN: null,
    NegativeNaN: null
}

I will create tests when I have the chance.

Date / time support

Most of the methods I've seen for encoding dates and times in JSON seem hacky and non-standard; if you're going to update the standard, doing dates in a nice way would be good.

(I'm not sure what that nice way would be)

JSON5.stringify should avoid quoting keys where appropriate

Currently, JSON5.stringify just delegates to JSON.stringify. The result does not seem very JSON5 to me. It makes sense that strings produced by JSON5 should be the shortest string that JSON5 can still parse and produce the original object.

So, one enhancement would be to remove quotes around keys that are already valid JS identifiers.

Since this would break compatibility with the builtin JSON object, perhaps a new function could be created (eg- stringify5).

Allow negative hexadecimal literals again

I just hooked up Travis CI support, which is great for testing across multiple versions of Node, and indeed, one of our test cases fails on Node 0.9:

https://travis-ci.org/aseemk/json5/jobs/4405590

The test case is parsing -0xC8, a negative hexadecimal literal. I narrowed the problem down to these lines in the parser:

https://github.com/aseemk/json5/blob/v0.1.0/lib/json5.js#L154-L156

number = +string;
if (!isFinite(number)) {
    error("Bad number");

The problem is that converting the string -0xC8 to a number via the unary + operator used to work, but now returns NaN. This changed from Node 0.8 to 0.9.

I investigated, and indeed, this is a breaking change in V8, but a fix technically:

http://code.google.com/p/v8/issues/detail?id=2240

I'm not sure yet what this means for JSON5, but we have one failing test today on Node 0.9. We don't document that negative hexadecimal literals are supported anywhere, so I think we're fine there, and the parser correctly rejects them, but we should change the test. Not sure how to do this without causing test failures on Node 0.6 and 0.8.

/cc @MaxNanasy FYI =)

remove package.json

It is generally a bad idea to have generated file and source file in the same git repository because it's a pain to keep both in sync.

Also, JSON has an ugly syntax, and doesn't support comments. I wonder why people would even think about using that? :)

Besides, some npm forks are able to work with package.json5 files for 2 months now. So you shouldn't even need to compile anything. :P

// ref #13

Portable test data set

I want to port JSON5 to another programming language.
Is there a portable test data set?

mime type

I'm slowly pushing json5 to production systems in a backward compatible manner (which means strict json on the output, expecting json5 on the input).

Since we do expect json5 on the input, we should recognize its mime type as well. Sadly, there is none.

So the question is: what mime type are you planning to register/use in the future?

Add trailing comma in formatted stringify

Since one of the goals of JSON5 is to be more easily writable for humans, and since I happened to find this project by Googling "json trailing comma", I think it makes sense for JSON5 to output text that is more easily writable for humans too.

The examples in the README would be output as (note the added trailing commas):

{
    foo: "bar",
    while: true,
    this: "is a multi-line string",
    here: "is another",
    hex: 3735928559,
    half: 0.5,
    delta: 10,
    to: null,
    finally: "a trailing comma",
    oh: [
        "we shouldn't forget",
        "arrays can have",
        "trailing commas too",
    ],
}
{
    name: "json5",
    version: "0.2.0",
    description: "JSON for the ES5 era.",
    keywords: [
        "json",
        "es5",
    ],
    author: "Aseem Kishore <[email protected]>",
    contributors: [
        "Max Nanasy <[email protected]>",
    ],
    main: "lib/json5.js",
    bin: "lib/cli.js",
    dependencies: {},
    devDependencies: {
        mocha: "~1.0.3",
    },
    scripts: {
        build: "./lib/cli.js -c package.json5",
        test: "mocha --ui exports --reporter spec",
    },
    homepage: "http://json5.org/",
    repository: {
        type: "git",
        url: "https://github.com/aseemk/json5.git",
    },
}

Of course, this would only be when the space argument is specified with a truthy value. Otherwise, JSON5 should probably output text as compact as possible.

Thoughts?

rationale

This project makes JSON harder to parse and maintain because introduces a lot of ambiguity (like traling commas, quoted / unquoted properties, etc) and kills the purpose of JSON (which should be language agnostic and fast to parse). Are you aware of this?

isWord becomes property of JSON5 after calling stringify

> node -i

> JSON5 = require('json5')
{ parse: [Function], stringify: [Function] }

> JSON5.stringify()
undefined

> JSON5
{ parse: [Function],
  stringify: [Function],
  isWord: [Function: isWord] }

I understand the rationale behind this line of code. But maybe it would be better to move these functions like isWord into their own "helper" module to avoid leaking.

Thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.