Skip to content

Instantly share code, notes, and snippets.

@wilg
Last active September 10, 2019 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilg/0a2961601a391688dd7f33e812bdfb02 to your computer and use it in GitHub Desktop.
Save wilg/0a2961601a391688dd7f33e812bdfb02 to your computer and use it in GitHub Desktop.
ESON (or: yet another stab at slightly improving JSON)
// ESON is like JSON.
// ESON files should use the `.eson` file extension and the `application/eson` MIME type.
// This is meant to be as close to JSON as possible (and backwards compatible), but having learned a few lessons.
{
// It's backwards compatible with JSON.
"key": "value",
// Obviously, the big feature is it supports comments:
/*
I removed comments from JSON because I saw people were using them to hold parsing directives,
a practice which would have destroyed interoperability. I know that the lack of comments makes
some people sad, but it shouldn't.
- Douglas Crockford, 2012
*/
// The above concern is valid, and ESON is a little less interoperable. But a little nicer. Trade offs!
// But it does mean you can use comments for parsing directives (or streaming hints) if you want.
// Though there's a better way we'll talk about later.
// It supports one new kind of string, stolen from ES. These are delimited with backticks.
`key`: `value`,
// This lets you use multiline strings:
`like
this`: `which is a
contrived
example
sorry`,
// Or put single or double quotes inside:
`single 'quotes'`: `and "double quotes"`,
// It also supports unquoted keys, like ES.
so_this_is: "totally fine",
// And, to add insult to injury, like ES, the new backtick strings support tags.
atag`on both the keys`: anothertag`and values`,
// Parsers probably should just drop the tags by default, but you should be able to
// fish them out somehow to let applications provide data type hints.
// But they can always fall back to JSON data types if they receive unknown tags.
date: iso8601`2019-09-09T23:19:42+00:00`,
id`user`: 645,
// The only other difference is that trailing commas are allowed:
numbers: [
1,
2,
3,
],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment