JSON5 • HJSON • HanSON • SON • TJSON • CSON • USON • JSONX • JSON11 • JSON XI • JSONII • JSON Lines • NDJSON • HOCON • HCL • UCL
A Collection of What's Next for Awesome JSON (JavaScript Object Notation) for structured (meta) data in text.
- Comments, Comments, Comments
- Unquoted Keys
- Multi-Line Strings
- a) Folded -- Folds Newlines
- b) Unfolded
- Trailing Commas in Arrays and Objects
More:
- Date/DateTime/Timestamp Type
- Optional Commas
- Optional Unquoted String Values
- "Raw" String (e.g.
''
instead of""
)- No need to escape
\
or"
etc. To escape'
use'''
e.g.''''Henry's Themes'''
- No need to escape
- More Data Types (
set
,map
,symbol
, etc.) - And much more
Fixing JSON - Comments, Please!
We can easily agree on what’s wrong with JSON, and I can't help wondering if it'd be worth fixing it.
-- Tim Bray (Fixing JSON)
XML already does everything JSON does! And there's no way to differentiate between nodes and attributes! And there are no namespaces! And no schemas! What's the point of JSON?
-- Anonymous
We need to fix engineers that try to 'fix JSON', absolutely nothing is broken with JSON.
-- Anonymous
- Fixing JSON by Tim Bray, Aug 2016
- Major Irritant: Commas • Irritant: Timestamps • Major irritant: Schemas
- The Fixing-JSON Conversation by Tim Bray, Aug 2016
- Just use X • Comments, please please comments! • You shouldn't want to hand-edit JSON • You'll lose JavaScript compatibility! • Unquoted field names, please! • Is it too late?
- Fixing JSON Comments @ Hacker News, Aug 2016
JSON5 • HJSON • HanSON • SON • JSONX • CSON • USON
Modern JSON - JSON for the ES5 Era
JSON for "Humans" (not Machines). Adds:
- Comments- Allow both inline (single-line) and block (multi-line) comments are allowed (like ES5)
- Keys can be unquoted if they're valid identifiers e.g. a-z0-9 (like ES5)
- Single and double quoted strings (like ES5)
- Allows multi-line string with backslash (like ES5)
- Allow trailing commas for arrays and objects.
- And some more.
// This file is written in JSON5 syntax, naturally, but npm needs a regular
// JSON file, so compile via `npm run build`. Be sure to keep both in sync!
{
name: 'json5',
version: '0.5.0',
description: 'JSON for the ES5 era.',
keywords: ['json', 'es5'],
author: 'Aseem Kishore <[email protected]>',
contributors: [
// TODO: Should we remove this section in favor of GitHub's list?
// https://github.com/json5/json5/contributors
'Max Nanasy <[email protected]>',
'Andrew Eisenberg <[email protected]>',
'Jordan Tucker <[email protected]>',
],
main: 'lib/json5.js',
bin: 'lib/cli.js',
files: ["lib/"],
dependencies: {},
devDependencies: {
gulp: "^3.9.1",
'gulp-jshint': "^2.0.0",
jshint: "^2.9.1",
'jshint-stylish': "^2.1.0",
mocha: "^2.4.5"
},
scripts: {
build: 'node ./lib/cli.js -c package.json5',
test: 'mocha --ui exports --reporter spec',
// TODO: Would it be better to define these in a mocha.opts file?
},
homepage: 'http://json5.org/',
license: 'MIT',
repository: {
type: 'git',
url: 'https://github.com/json5/json5',
},
}
A "Human" User Interface for JSON
- Commas Optional
- Add comments, hash-style (#), line-style (//) and block-style (/* */)
- Allow Keys without quotes
- Allow Strings without quotes
- Allow Multi-line strings Python-style e.g. ''' text '''
{
// use #, // or /**/ comments,
// omit quotes for keys
key: 1
// omit quotes for strings
contains: everything on this line
// omit commas at the end of a line
cool: {
foo: 1
bar: 2
}
// allow trailing commas
list: [
1,
2,
]
// and use multiline strings
realist:
'''
My half empty glass,
I will fill your empty half.
Now you are half full.
'''
}
JSON for Humans
github: timjansen/hanson
Adds:
- HanSON is JSON with comments, multi-line strings and unquoted property names.
- Comments use JavaScript syntax (
//
,/**/
). - Supports backticks as quotes (``) for multi-line strings.
- You can use either double-quotes (
""
) or single-quotes (''
) for single-line strings. - Property names do not require quotes if they are valid JavaScript identifiers.
- Commas after the last list element or property will be ignored.
- Every JSON string is valid HanSON.
- HanSON can easily be converted to real JSON.
{
listName: "Sesame Street Monsters", // note that listName needs no quotes
content: [
{
name: "Cookie Monster",
/* Note the template quotes and unescaped regular quotes in the next string */
background: `Cookie Monster used to be a
monster that ate everything, especially cookies.
These days he is forced to eat "healthy" food.`
}, {
// You can single-quote strings too:
name: 'Herry Monster',
background: `Herry Monster is a furry blue monster with a purple nose.
He's mostly retired today.`
}, // don't worry, the trailing comma will be ignored
]
}
Simple Object Notation
github: aleksandergurin/simple-object-notation
Adds:
- comments starts with # sign and ends with newline (\n)
- comma after a key-value pair is optional
- comma after an array element is optional
{
# Personal information
"name": "Alexander Grothendieck"
"fields": "mathematics"
"main_topics": [
"Etale cohomology"
"Motives"
"Topos theory"
"Schemes"
]
}
JSON with Extensions (JSONX) or JSON v1.1 (a.k.a. JSON11 or JSON XI or JSON II) - JSON Evolved for Humans - Easy-to-Write, Easy-to-Read
github: json-next
JSON v1.1 includes all JSON extensions from HanSON (JSON for Humans):
- quotes for strings are optional if they follow JavaScript identifier rules.
- you can alternatively use backticks, as in ES6's template string literal, as quotes for strings. A backtick-quoted string may span several lines and you are not required to escape regular quote characters, only backticks. Backslashes still need to be escaped, and all other backslash-escape sequences work like in regular JSON.
- for single-line strings, single quotes (
''
) are supported in addition to double quotes (""
) - you can use JavaScript comments, both single line (
//
) and multi-line comments (/* */
), in all places where JSON allows whitespace. - Commas after the last list element or object property will be ignored.
Plus all JSON extensions from SON (Simple Object Notation):
- comments starts with
#
sign and ends with newline (\n
) - comma after an object key-value pair is optional
- comma after an array item is optional
Example:
{
# use shell-like comments
listName: "Sesame Street Monsters" # note: comments after key-value pairs are optional
content: [
{
name: "Cookie Monster"
// note: the template quotes and unescaped regular quotes in the next string
background: `Cookie Monster used to be a
monster that ate everything, especially cookies.
These days he is forced to eat "healthy" food.`
}, {
// You can single-quote strings too:
name: 'Herry Monster',
background: `Herry Monster is a furry blue monster with a purple nose.
He's mostly retired today.`
}, /* don't worry, the trailing comma will be ignored */
]
}
Cursive Script Object Notation (CSON). A strict superset of JavaScript Object Notation (JSON) that can be written by hand (hence the name) and translated to a canonical JSON
github: lifthrasiir/cson - designed by Kang Seonghoon
CSON:
# CSON data example
hello =
|world
| ...and goodbye
the = ['answer', 'is'
42]
same as:
{
"hello": "world\n ...and goodbye",
"the": ["answer", "is",
42]
}
CoffeeScript-Object-Notation. Same as JSON but for CoffeeScript objects
github: bevry/cson
CSON:
# Comments!!!
# An Array with no commas!
greatDocumentaries: [
'earthlings.com'
'forksoverknives.com'
'cowspiracy.com'
]
# An Object without braces!
importantFacts:
# Multi-Line Strings! Without Quote Escaping!
emissions: '''
Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.
Goodland, R Anhang, J. “Livestock and Climate Change: What if the key actors in climate change were pigs, chickens and cows?”
WorldWatch, November/December 2009. Worldwatch Institute, Washington, DC, USA. Pp. 10–19.
http://www.worldwatch.org/node/6294
'''
landuse: '''
Livestock covers 45% of the earth’s total land.
Thornton, Phillip, Mario Herrero, and Polly Ericksen. “Livestock and Climate Change.” Livestock Exchange, no. 3 (2011).
https://cgspace.cgiar.org/bitstream/handle/10568/10601/IssueBrief3.pdf
'''
burger: '''
One hamburger requires 660 gallons of water to produce – the equivalent of 2 months’ worth of showers.
Catanese, Christina. “Virtual Water, Real Impacts.” Greenversations: Official Blog of the U.S. EPA. 2012.
http://blog.epa.gov/healthywaters/2012/03/virtual-water-real-impacts-world-water-day-2012/
“50 Ways to Save Your River.” Friends of the River.
http://www.friendsoftheriver.org/site/PageServer?pagename=50ways
'''
milk: '''
1,000 gallons of water are required to produce 1 gallon of milk.
“Water trivia facts.” United States Environmental Protection Agency.
http://water.epa.gov/learn/kids/drinkingwater/water_trivia_facts.cfm#_edn11
'''
more: 'http://cowspiracy.com/facts'
same as:
{
"greatDocumentaries": [
"earthlings.com",
"forksoverknives.com",
"cowspiracy.com"
],
"importantFacts": {
"emissions": "Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.\nGoodland, R Anhang, J. “Livestock and Climate Change: What if the key actors in climate change were pigs, chickens and cows?”\nWorldWatch, November/December 2009. Worldwatch Institute, Washington, DC, USA. Pp. 10–19.\nhttp://www.worldwatch.org/node/6294",
"landuse": "Livestock covers 45% of the earth’s total land.\nThornton, Phillip, Mario Herrero, and Polly Ericksen. “Livestock and Climate Change.” Livestock Exchange, no. 3 (2011).\nhttps://cgspace.cgiar.org/bitstream/handle/10568/10601/IssueBrief3.pdf",
"burger": "One hamburger requires 660 gallons of water to produce – the equivalent of 2 months’ worth of showers.\nCatanese, Christina. “Virtual Water, Real Impacts.” Greenversations: Official Blog of the U.S. EPA. 2012.\nhttp://blog.epa.gov/healthywaters/2012/03/virtual-water-real-impacts-world-water-day-2012/\n“50 Ways to Save Your River.” Friends of the River.\nhttp://www.friendsoftheriver.org/site/PageServer?pagename=50ways",
"milk": "1,000 gallons of water are required to produce 1 gallon of milk.\n“Water trivia facts.” United States Environmental Protection Agency.\nhttp://water.epa.gov/learn/kids/drinkingwater/water_trivia_facts.cfm#_edn11",
"more": "http://cowspiracy.com/facts"
}
}
μson - A compact human-readable data serialization format specially designed for shell
github: burningtree/uson
Principles:
- Superset of JSON (every JSON is valid μson).
- Whitespace is not significant.
- String quoting
"
is optional. - In Array or Object, comma
,
can be replaced by whitespace - Assignation with colon
:
can be repeated to create nested objects. - You can use own types, casting is done by
!
character.
USON:
number:12.05 text:Banana quotedText:"John Devilseed" empty:null good:true
same as:
{
"number": 12.05,
"text": "Banana",
"quotedText": "John Devilseed",
"empty": null,
"good": true
}
USON:
simple:[1 2 3] texts:[Malta Budapest "New York"] objects:[{id:1}]
same as:
{
"simple": [
1,
2,
3
],
"texts": [
"Malta",
"Budapest",
"New York"
],
"objects": [
{
"id": 1
}
]
}
Tagged JSON with Rich Type Annotations
A tagging scheme/microformat for enriching the types stored in self-describing, schema-free JSON documents.
Why? Enables "content-aware hashing" where different encodings of the same data (including both TJSON and binary formats like Protocol Buffers, MessagePack, BSON, etc) share the same content hash and therefore the same cryptographic signature.
TJSON supports the following data types:
- Objects (O): Name/value dictionaries. The names of objects in TJSON carry a postfix "tag" which acts as a type annotation for the associated value.
- Arrays (A): Lists of values: identical to JSON, but typed by their containing objects. Unlike JSON, arrays cannot be used as a top-level expression: only objects are allowed.
- Sets (S): Lists of unique values: similar to an array, but repeated elements are disallowed.
- Strings (s): TJSON strings are Unicode and always serialized as UTF-8. When used as the name of a member of an object, they carry a mandatory "tag" which functions as a self-describing type annotation which provides a type signature for the associated value.
- Binary Data (d, d16, d32, d64): First-class support for 8-bit clean binary data, encoded in a variety of formats including hexadecimal (a.k.a. base16), base32, and base64url.
- Numbers:
- Integers (i,u): TJSON supports the full ranges of both signed and unsigned 64-bit integers by serializing them as strings.
- Floating points (f): Floating point numbers in TJSON are identical to JSON, but can always be disambiguated from integers.
- Timestamps (t): TJSON has a first-class type for representing date/time timestamp values, serialized as a subset of RFC 3339 (an ISO 8601-alike).
- Boolean Values (b): TJSON supports the true and false values from JSON (null is expressly disallowed).
Examples:
{
"array-example:A<O>": [
{
"string-example:s": "Hello, world!",
"binary-data-example:d": "QklOQVJZ",
"float-example:f": 0.42,
"int-example:i": "42",
"timestamp-example:t": "2020-11-06T22:27:34Z",
"boolean-example:b": true
}
],
"set-example:S<i>": [1, 2, 3]
}
One Line, One Data Record
web: jsonlines.org
One Line, One Record - Newline (nl or \n) Separated
["Name", "Session", "Score", "Completed"]
["Gilbert", "2013", 24, true]
["Alexa", "2013", 29, true]
["May", "2012B", 14, false]
["Deloise", "2012A", 19, true]
Pros:
- Supports JSON Datatypes (Numbers, Bool, Null, etc.)
or nested data records e.g.
{"name": "Gilbert", "wins": [["straight", "7♣"], ["one pair", "10♥"]]}
{"name": "Alexa", "wins": [["two pair", "4♠"], ["two pair", "9♠"]]}
{"name": "May", "wins": []}
{"name": "Deloise", "wins": [["three of a kind", "5♣"]]}
Newline Delmited JSON
web: ndjson.org, github: ndjson
- Line Separator is '\n'
- Each Line is a valid JSON Value
{"some":"thing"}
{"foo":17,"bar":false,"quux":true}
{"may":{"include":"nested","objects":["and","arrays"]}}
(Source: specs.okfnlabs.org/ndjson)
: = {} []
Human-Optimized Config Object Notation
github: typesafehub/config/HOCON
HashiCorp Configuration Language
github: hashicorp/hcl
Universal Configuration Language
github: vstakhov/libucl
AXON is eXtended Object Notation
web: intellimath.bitbucket.io/axon
Objective Markup Notation, abbreviated as Mark or {mark} - a unified notation for both object and markup data
web: mark.js.org, github: henry-luo/mark
See Format Extensions, Supersets and Related Formats in Awesome JSON (@burningtree)
- JSON: The Fat-Free Alternative to XML by Douglas Crockford
- Parsing JSON is a Minefield by Nicolas Seriot
License
The awesome list is dedicated to the public domain. Use it as you please with no restrictions whatsoever.
Questions? Comments?
Post them to the wwwmake forum. Thanks!