First, Dump the Strings
Did you notice what’s missing from the main page example? Strings are not needed to write a wide range of datatypes:
user-database: [
{
name: "John Smith"
age: 22
born: 1998-8-15
usage: 8:22:45
email: jsmith@altscript.com
website: http://altscript.com
version: 3.2.14
passhash: #A94A8FE5CCB19BA6
colors: [ 255.100.50 50.50.80 ]
allow: [ login admin upload edit ]
check: [ if age > 60 [ add-to people.seniors ]]
}
{ ... more users ... }
]
Sure, JSON format supports booleans (true/false), integers, floats, and strings, but if you need other data-types, you write them as strings, and convert them separately.
Imagine if you could write this JSON:
[ "JSON", "2021-10-14", "10:30", "$123.45",
"bob@altscript.com", "138.197.200.83", "<div>", "A4B5C6" ]
as this in ASON:
[ ASON 2021-10-14 10:30 $123.45 jsmith@altscript.com
138.197.200.83 <div> #A4B5C6 ]
ASON supports strings, integers, floats, and booleans, but also symbols (words), dates, times, currency, versions, email addresses, network addresses, hypertext tags, and hexadecimal and base-64 binary. When ASON parses it, the data-type of each value is detected and converted automatically. This makes it much easier to use in programs.
No Commas
Notice that JSON requires commas, and ASON does not. This is more important that it first seems.
First, since values are always separated by white-space, commas are not really necessary. They are just syntactic sugar.
But, more importantly, commas make it difficult for arrays to represent code. Sure, you could write a code statement in JSON like this:
[ "if", "time", ">", "10:30", [ "signal", "wakeup" ] ]
But, the commas get in the way. They mess it up. In ASON you’d simply write:
[ if time > 10:30 [ signal wakeup ] ]
This pretty clearly shows the advantage of comma free arrays as well as the benefit of words as symbols rather than strings.
Allows Symbols
The above example shows another important difference. In ASON, you can use words as symbols. When they are parsed, words are tokenized and stored in a symbol table. This makes the word a simple value that can be assigned meaning.
Although it may not be obvious, JSON actually does this for booleans true and false. It lets you reference those words directly. They are not strings. They have special meaning by not being strings. They are symbols.
And that’s the power of symbols that’s generalized in ASON. Take this ASON example where the word print
is used to indicate a special action:
[ print "Hello" ]
There’s no equivalent in JSON. It does not support symbols. Both elements would need to be strings, written this way:
[ "print", "Hello" ]
But now it’s not clear that print
is a special action. There’s nothing to denote it from being a string.
Cleaner Objects
JSON objects are collections of key-value pairs where the keys are written as strings. Here’s an example
{
"name": "John Smith",
"age": 27,
"debt": 120.35,
"licensed": true
"allow": [ "admin", "edit", "save", "delete" ]
}
In ASON, the key values are words, not strings. The above would be written like this:
{
name: "John Smith"
age: 27
debt: 120.35
licensed: true
allow: [ admin edit save delete ]
}
If you’ve used JavaScript objects, then you’re familiar with this format. It’s cleaner and simpler, but it also lets the key values be referenced as words in a way that makes code possible. For example, in ASON you could write:
[ print [ name "owes" debt "dollars" ] ]
Of course, this is an example of an unnamed object, and the words above must be bound to the object context, but more about objects will be covered in the AltScript pages.