Last active
August 29, 2015 13:56
-
-
Save cowboy/8829466 to your computer and use it in GitHub Desktop.
Why do we keep having the "comments in JSON" discussion? Just use YAML.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
# this is a comment | |
"a": "hello", | |
# this is another comment | |
"b": -1, | |
"c": [ | |
true, | |
"test", | |
null | |
], | |
# yet another comment | |
"d": { | |
"x": 1, | |
"y": 2 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is a comment | |
a: hello | |
# this is another comment | |
b: -1 | |
c: | |
- true | |
- "test" | |
- null | |
# yet another comment | |
d: | |
x: 1 | |
y: 2 |
If you want to use a YAML configuration file on the server/command line, there are YAML libraries for most languages. For example, Grunt's grunt.file.readYAML method uses the npm js-yaml module.
If you need to use data stored in YAML in the browser, you can compile all your YAML files into JSON before sending them to the client, as part of your build process with a Grunt plugin like grunt-yaml (I haven't tested it, personally).
May have to copy this idea!
:)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See how a YAML parser parses: