{"id":72,"date":"2020-12-29T21:42:45","date_gmt":"2020-12-30T05:42:45","guid":{"rendered":"https:\/\/altscript.com\/?page_id=72"},"modified":"2021-01-09T12:07:37","modified_gmt":"2021-01-09T20:07:37","slug":"ason-vs-json","status":"publish","type":"page","link":"https:\/\/altscript.com\/?page_id=72","title":{"rendered":"ASON vs JSON"},"content":{"rendered":"\n<h2>First, Dump the Strings<\/h2>\n\n\n\n<p>Did you notice what&#8217;s missing from the main page example? Strings are not needed to write a wide range of datatypes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>user-database: &#91;\n  {\n    name: \"John Smith\"\n    age:  22\n    born: 1998-8-15\n    usage: 8:22:45\n    email: jsmith@altscript.com\n    website: http:\/\/altscript.com\n    version: 3.2.14\n    passhash: #A94A8FE5CCB19BA6\n    colors: &#91; 255.100.50 50.50.80 ]\n    allow: &#91; login admin upload edit ]\n    check: &#91; if age &gt; 60 &#91; add-to people.seniors ]]\n  }\n  { ... more users ... }\n]<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Imagine if you could write this JSON:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91; \"JSON\", \"2021-10-14\", \"10:30\", \"$123.45\",\n  \"bob@altscript.com\", \"138.197.200.83\", \"&lt;div&gt;\", \"A4B5C6\" ]<\/code><\/pre>\n\n\n\n<p>as this in ASON:<\/p>\n\n\n\n<pre id=\"block-1c0bcdcf-2b2b-4ee1-9575-2b594fa334ff\" class=\"wp-block-code\"><code>&#91; ASON 2021-10-14 10:30 $123.45 jsmith@altscript.com\n  138.197.200.83 &lt;div&gt; #A4B5C6 ]<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<h2>No Commas<\/h2>\n\n\n\n<p>Notice that JSON requires commas, and ASON does not. This is more important that it first seems.<\/p>\n\n\n\n<p>First, since values are always separated by white-space, commas are not really necessary. They are just syntactic sugar.<\/p>\n\n\n\n<p>But, more importantly, commas make it difficult for arrays to represent code. Sure, you could write a code statement in JSON like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91; \"if\", \"time\", \"&gt;\", \"10:30\", &#91; \"signal\", \"wakeup\" ] ]<\/code><\/pre>\n\n\n\n<p>But, the commas get in the way. They mess it up. In ASON you&#8217;d simply write:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91; if time &gt; 10:30 &#91; signal wakeup ] ]<\/code><\/pre>\n\n\n\n<p>This pretty clearly shows the advantage of comma free arrays as well as the benefit of words as symbols rather than strings.<\/p>\n\n\n\n<h2>Allows Symbols<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>And that&#8217;s the power of symbols that&#8217;s generalized in ASON. Take this ASON example where the word <code>print<\/code> is used to indicate a special action:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91; print \"Hello\" ]<\/code><\/pre>\n\n\n\n<p>There&#8217;s no equivalent in JSON. It does not support symbols. Both elements would need to be strings, written this way:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91; \"print\", \"Hello\" ]<\/code><\/pre>\n\n\n\n<p>But now it&#8217;s not clear that <code>print<\/code> is a special action. There&#8217;s nothing to denote it from being a string.<\/p>\n\n\n\n<h2>Cleaner Objects<\/h2>\n\n\n\n<p>JSON objects are collections of key-value pairs where the keys are written as strings. Here&#8217;s an example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"name\": \"John Smith\",\n    \"age\":  27,\n    \"debt\": 120.35,\n    \"licensed\": true\n    \"allow\": &#91; \"admin\", \"edit\", \"save\", \"delete\" ]\n}<\/code><\/pre>\n\n\n\n<p>In ASON, the key values are words, not strings. The above would be written like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    name: \"John Smith\"\n    age:  27\n    debt: 120.35\n    licensed: true\n    allow: &#91; admin edit save delete ]\n}<\/code><\/pre>\n\n\n\n<p>If you&#8217;ve used JavaScript objects, then you&#8217;re familiar with this format. It&#8217;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:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91; print &#91; name \"owes\" debt \"dollars\" ] ]<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>First, Dump the Strings Did you notice what&#8217;s missing from the main page example? Strings are not needed to write a wide range of datatypes: 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/altscript.com\/index.php?rest_route=\/wp\/v2\/pages\/72"}],"collection":[{"href":"https:\/\/altscript.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/altscript.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/altscript.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/altscript.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=72"}],"version-history":[{"count":7,"href":"https:\/\/altscript.com\/index.php?rest_route=\/wp\/v2\/pages\/72\/revisions"}],"predecessor-version":[{"id":187,"href":"https:\/\/altscript.com\/index.php?rest_route=\/wp\/v2\/pages\/72\/revisions\/187"}],"wp:attachment":[{"href":"https:\/\/altscript.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}