Re: JSON / XML support in E

Thomas Leonard <tal-v5nx5w6akNyLE8xUarVfuPLx9OUvmyODWmv/[email protected]>
Newsgroups gmane.comp.lang.e.general
Organization IT Innovation
Message-ID <[email protected]>
On Sat, 2010-01-16 at 17:07 -0800, Mark Miller wrote:
> On Fri, Jan 15, 2010 at 4:47 AM, Kevin Reid <[email protected]> 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-v5nx5w6akNyLE8xUarVfuPLx9OUvmyODWmv/[email protected]
http://www.it-innovation.soton.ac.uk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.