[e-lang] Representing object graphs in JSON

David-Sarah Hopwood david-sarah at jacaranda.org
Fri May 22 12:56:55 EDT 2009

Kevin Reid wrote:
> On May 18, 2009, at 10:20, Tyler Close wrote:
>> http://waterken.sourceforge.net/web_send/#JSONvalue
> If I added support for your "=" I would also add "@", "!", and "$" and  
> produce a "represent arbitrary Data-E as Waterken-JSON" library --  
> this may in fact become part of my [Google Summer of Code]
> CapTP-on-Caja project this year.

It might be worth looking at JSON-RPC as a way to avoid

Of course JSON-RPC is an RPC protocol, so it does not support
promise pipelining and is not capability-based. However, it seems
to me that if you started with JSON-RPC 2.0, which is an admirably
simple and uncluttered protocol, and layered those features on top
of it using CapTP, then the resulting layering (for example,
CapTP over JSON-RPC over HTTP over TLS) would be reasonable and
the JSON-RPC layer would not be contributing redundant complexity.
That might also simplify interacting with plain JSON-RPC over HTTP
services from Waterken or Caja or E.

> (Hm, though you don't AFAIK have any syntax for cycles? You have "@",  
> and {"@": "#foo"} is well-defined, but there is no convention for  
> *defining* fragments of a JSON tree. Could you suggest one so I don't  
> have to?)

I know of two main existing approaches to representing cycles and sharing
(i.e. arbitrary object graphs) in JSON or as an extension to JSON:

1. "JSON referencing", proposed by Kris Zyp.
   See <http://markmail.org/message/vted6u4y7d6c6pz5> and links
   from there, especially
   (note that the syntax has changed since that post to use '#').

   API docs:
   <http://api.dojotoolkit.org/jsdoc/1.3/dojox.json.ref> or

2. The "sharp variable" format, borrowed from Common Lisp by
   Brendan Eich and used internally in Mozilla software
   (for example it is used by Firefox to store saved browser sessions).

   This is *briefly* documented at
   (What is not made entirely clear by that documentation is that
   sharp variables are accepted by SpiderMonkey as an extension to
   JavaScript syntax, not just as an output format:

JSON referencing is a way of encoding cycles within the standard
JSON syntax, while sharp variables are a syntactic extension.
Sharp variables seem simpler to me, but if you want to stay within
standard JSON, then JSON referencing seems to be the only proposal
I can find that might have legs as a potentially more-widely-used

I have cc:d Kris Zyp in case he has any comments. (Kris: e-lang
is a subscriber-only-posting list, so I will forward.)

David-Sarah Hopwood ⚥

More information about the e-lang mailing list