Update: Note has been replaced by Space: https://github.com/breck7/space
Note is a concise encoding for hash tables.
Note is designed to make it easy for both humans and programmers to read, write, edit, and share hash tables.
Here's how I could encode data about myself:
firstName Breck
lastName Yunits
birthday 02/26/1984
email [email protected]
Here's how I could encode a tax return:
socialSecurityNumber 555-55-5555
name John Smith
taxYear 2012
income 10,000
dependents 1
exemptions 2
address 123 Main Street
city San Francisco
state California
Here's how I could encode nested analytics about a website:
/homepage
pageviews 2312
uniques 231
referers
/about 23
/contact 41
/about
pageviews 314
uniques 201
referers
/home 100
/contact 21
/contact
pageviews 214
uniques 124
referers
/home 110
/about 10
Human Readable. Note has no syntax characters other than whitespace to make it easy to read and edit. Unlike other languages such as XML or JSON, Note is designed to be easy for beginner programmers and complete laypersons to read and edit.
Concise. Note has just a few features to make it simple and broadly usable. There are no syntax characters other than whitespace, no types other than strings and nested hash tables, and Note uses the smallest amount of whitespace possible to establish structure. Unlike other whitespace languages which use 2-4 spaces (or the tab character), Note only uses a single space to indent an item or a single newline to seperate key/value pairs.
Extendable. Note is useful to solve many problems as is. However, Note is designed to be extendable. Although Note has no types other than hash tables and strings, you can build domain specific languages on top of Note that expect other types as encoded strings. Example: https://github.com/breck7/blocks
The following is a higher level overview of the spec. The actual technical spec can be read here: https://github.com/breck7/note/blob/master/spec.txt
Data Structures. Note is a serialization format for recursive hash tables. Note uses 2 data structures: hash tables and strings.
Syntax Characters. Note has two special characters:
- The Space Character.
- The New Line Character.
A Note object is simply a hash table. A single space character(" ") separates a name with its value. A newline separates pairs. Names are always strings. Names can contain any character except space or newline. Values can be either strings or nested Note objects and can contain any character. A newline plus indented space indicates a nested hash table.
Note does not care what programming language you use. Although the implementation of Note included here is built in Javascript, Note can be read, written, and modified easily with any programming language. In fact, one of the main benefits of Note is that it can be used by many programs, with many different languages, and they can all easily share hash tables using Note.
More implementations are coming soon.
email [email protected]
In the Note object above, "email" is a name, and "[email protected]" is the corresponding value.
email [email protected]
gender male
In the Note object above, "email" and "gender" are names, and "[email protected]" and "male" are the corresponding values.
You can set values as strings like in the examples above, or you can set values to be nested Note objects by putting a newline immediately after the name and by indenting each item in the nested Note object by 1 space.
email [email protected]
gender male
phone_numbers
home 555-5555
cell 444-4444
In this example, the value of phone_numbers is itself another Note object.
email [email protected]
gender male
phone_numbers
home 555-5555
cell 444-4444
biography This is my bio.
It it written on multiple lines.
There is a space after biography above, which instructs the code that this is
a multiline string, and not a nested Note object.
The end.
Values can be multiline strings by adding a space after the name (in this case "biography") and indenting the additional lines by one space.
- Visit http://noteapi.com to play with some popular APIs using Note.
- See https://github.com/breck7/blocks for an example of a higher level encoding built on Note.
Although Note has no types and very few features, you can easily build encodings on top of Note that do have types and additional features. Your extension can expect a leaf to follow a certain encoding (ie: HTML, JSON, CSV, Markdown, Base64, et cetera.).
For example, you could build a class called Person, that extends note, and expects a JSON encoded array for the favorite_colors property.
function Person (note) {
this.patch(note)
if (this.favorite_colors)
this.favorite_colors = JSON.parse(this.favorite_colors)
}
Person.prototype = new Note()
var joe = new Person('favorite_colors ["blue", "red", "green"]')
console.log(joe.favorite_colors[0])
// prints "blue"
console.log(joe.favorite_colors[2])
// prints "green"
The Javascript library in this repo works in both the browser and with Node.js.
The API in the Javascript implementation is still somewhat in flux, but there are many neat methods such as diff, patch, and toString that demonstrate some neat features of Note.
If you'd like to contribute please contact me at [email protected].
Feel free to contact me at [email protected] for help using or extending Note.
This object, with spaces in the name, cannot be represented in Note:
{ "This name has a space" : "value" }
To get around this you could rename the name, or use camelCasing or underscores instead of spaces.
A Note is a hash table and not an array, and so:
winners
joe
bob
sam
is equivalent to
winners
bob
joe
sam
If order is important for your application, you could specify the numbers:
winners
1 joe
2 bob
3 sam
OR you can make your code expect a leaf node to contain an array type:
winners joe bob sam
winners ['joe', 'bob', 'sam]
winners joe,bob,sam
Note was inspired mostly by JSON and HAML, a bit by XML and YAML, and our personal desire for a simple, powerful encoding with less syntax.