# Syntax

# Cheatsheet

This document shows the features of the Jsonic syntax:

// jsonic                              // JSON

  // cheat...       # comments
  /*
   * ...sheet!
   */
                    # implicit top level    { 
  a:                # implicit null           "a": null,

  b: 1              # optional comma           "b": 1,
  c: 1
  c: 2              # last duplicate wins      "c": 2,
  
  d: f: 3           # key chains               "d": {
  d: g: h: 4        # object merging           "f": 3,
                                                 "g": {
                                                   "h": 4
                                                 }   
                                               }
                                      
TODO
                                             }

# Railroad Diagrams

jsonic

After parsing, either an object (map), an array (list), or a scalar value is returned. An empty document is considered valid and returns undefined. While map and list are strictly redundant here as they can be children of value, implicit maps (no surrounding braces {}) and implicit lists (no surrounding square brackets []) are special cases at the top level.

map list value undefined

map

One or more keys may preceed a value, creating child maps as needed. Missing values are null. Spurious commas are not allowed. Key-value pairs can be separated by space and new lines.

{ key : value sep }

list

List values are separated by space, commas and new lines. A trailing comma is ignored. A comma without a preceding value inserts an implicit null.

[ value sep ]

value

A value can be surrounded by optional space (To match json.org, our non-empty space must be optional).

space map list string number true false null space

key

Keys are verbatim source characters including unquoted text, number and literal value representations, but excluding punctuation ({}[]...).

space string number true false null space

sep

Commas, spaces, new lines, and nothing, all separate values equivalently.

, space

space

There must be at least one space character in the space token (unlike json.org—thus we make space optional elsewhere as needed). Space can contain one or comments.

«0x20» space «0xA» linefeed «0xD» carriage return «0x9» horizontal tab comment

string

Quoted strings (using «"'`») work as in JavaScript, including escaping. Triple single quotes operate as backticks, but remove the indent from each line.

all-chars ∖ «\t \r\n\b\f\'"`{}[]:,/#» unquoted text " escaped-chars ∪ «'» " ' escaped-chars ∪ «"» ' ` all-chars ∖ «`» escaped-chars ` ''' all-chars ∖ "'''" escaped-chars indents removed '''

number

Number literals work as in JavaScript. Underscore can be used to separate digits.

0 - + 0 digits [1-9][0-9]* ∪ «_» . digits [0-9]* ∪ «_» e E digits [0-9]* ∪ «_» 0 x digits a-fA-F ∪ «_» o digits 0-7 ∪ «_» b digits 0-1 ∪ «_»

comment

Comments work as in JavaScript. Single line comments can also be introduced with «#». Balanced comments can nest.

/* all-chars ∖ "*/" */ // all-chars ∖ ("//" ∪ «\r\n») # all-chars ∖ ("#" ∪ «\r\n»)