Kid
Syntax
Kid (Keen Interface for Data) is a serialization format like JSON.
It is equivalent to JSON and differs only in syntax.
Kid looks exactly like Keen. It is just limited to data expressions with no variables, control flow, etc.
Valid Kid expressions are:
null, booleans, numbers and strings, using the exact same syntax as JSON. (()also returnsnull.)- Comma-separated or multi-line
newexpressions, corresponding to JSON arrays. - Named-new expressions, corresponding to JSON objects.
The json type is the type of a parsed JSON value.
Since Kid has the same data model as JSON, a parsed Kid value is also of type json.
Keen and Kid
In the above example, value is created using a variety of functions (such as named-new)
that return json.
Conveniently, the syntax is exactly the same as Kid.
This is also true for typed objects.
Below, the syntax to construct a point in Keen is the exactly the same same
as the syntax for the Kid expression that converts to it.
Since the syntax is the same, you can cut and paste data between Keen and Kid files.
It's also useful to be able to output a value in a format that is valid source code.
Empty values
Keen has a single syntax for empty values: ().
JSON has 3: null, [], and {}.
Usually you should just use () (which means null)
and expect the user to treat it the same as other empty values.
In cases where it does matter, use empty-array or empty-object.
This works the same in both Keen and Kid.
Using JSON values
subscript gets a value from a json value.
If it is not an object containing the key, this returns null (displayed as ()).
There are many functions named to that convert json to various types.
These typically throw an exception if the json value does not look like what is expected.
(Though as mentioned above, null is typically allowed as an empty array or object.)
See keen/json to see them.