[e-lang] JSON / XML support in E

Thomas Leonard tal at it-innovation.soton.ac.uk
Mon Feb 22 07:42:07 PST 2010


On Sat, 2010-01-16 at 17:07 -0800, Mark Miller wrote:
> On Fri, Jan 15, 2010 at 4:47 AM, Kevin Reid <kpreid at mac.com> wrote:
>         On Jan 15, 2010, at 6:12, Thomas Leonard wrote:
>         > OK, I can create JSON documents easily enough using
>         >
>         > def Term := <type:org.quasiliteral.term.Term>
>         > def serialised := (testData :Term).asText()
>         >
>         > This is nice and fast, and I assume it could produce XML in
>         a
>         > similar way.
>         
>         
>         Huh, I didn't know that worked except for leaf types. (I find
>         that the
>         relevant code is in
>         org.erights.e.meta.org.quasiliteral.astro.AstroGuardSugar.)

>         
> 
> Yes. The first test case at src/jsrc/org/quasiliteral/term/Term.updoc
> is
> 
>     ? [3=>4, "a"=>'x', [2,3]=>[4,5]]:Term
>     # value: term`{3: 4,
>     #              "a": 'x',
>     #              [2, 3]:
>     #                  [4, 5]}`
> 
> which exercises some of the interesting cases.

This fails though:

? def Term := <type:org.quasiliteral.term.Term>
? def jsonSurgeon := <elib:serial.deJSONKit>.makeSurgeon()

? def data := [["hello\nworld"]]
? def text := (data:Term).asText()
? def data2 := jsonSurgeon.unserialize(text)

? data == data2
# value: true

The pretty printing inserts a space into the string after the \n:

? println(text)
[["hello
 world"]]


-- 
Dr Thomas Leonard
IT Innovation Centre
2 Venture Road
Southampton
Hampshire SO16 7NP

Tel: +44 0 23 8076 0834
Fax: +44 0 23 8076 0833
mailto:tal at it-innovation.soton.ac.uk
http://www.it-innovation.soton.ac.uk 



More information about the e-lang mailing list