[langsec-discuss] TJSON: Tagged JSON with Rich Types

Tony Arcieri bascule at gmail.com
Thu Nov 3 03:20:26 UTC 2016


Based on feedback and various discussions I've had, I've come up with an
interesting proposal:

https://github.com/tjson/tjson-spec/issues/30

Instead of embedding type information in a string-by-string basis:

    {"s:foo": "s:bar"}

We can use objects as the one source-of-truth for all type information,
mandating an object as the only allowable root expression in the grammar,
and embedding a type signature as a postfix tag in the name/key of each
object member:

    {"foo:s": "bar"}

In this scheme, objects act as a self-describing record-like product type.
They describe the rest of the type information in what approaches a
somewhat familiar type signature syntax.

Previously the TJSON spec allowed arrays as a root expression as well,
however this syntax prevents arrays from

This means the only type allowed for member names is a string (which seems
fine to me). It slightly complicates some other TJSON use cases, such as
redaction. But otherwise I think it's an improvement.

Moving the type signature to a postfix tag like this means we can add
additional interpretations of arrays in a non-hacky way. Sets were proposed
as another non-scalar type, but incorporating them before was a bit non
hacky. Now we can define a syntax for non-scalar types, and to disambiguate
them let's use upper case type names:

- A: array
- S: set

Now we can specify a set of strings as something like a C++/Java-ish syntax:

    {"words:S<s>": ["foo", "bar", "baz"]}

Or a multi-dimensional array of integers as:

    {"dialpad:A<A<i>>": [["1","2","3"], ["4","5","6"], ["7","8","9]]}

Perhaps an array of objects?

    {"myobjects:A<O>": [{"foo:i":"1"},{"bar:i":"2"},{"baz:i":"3"}]}

I think this is an improvement, and also enforces homogenous types, which
would be more amenable to mapping to static type systems.

-- 
Tony Arcieri
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.langsec.org/pipermail/langsec-discuss/attachments/20161102/4014fec6/attachment.html>


More information about the langsec-discuss mailing list