Hi Jon,

this is really funny. Just of today I'm working on a similar problem. As
I don't know JSON, however, I tried a direct approach with JS. The
mechanism looks surprisingly similar to what you wrote.

> "http://localhost:8080/@json?*JsonCallback=?";, and my server script 
> does things like this
> (de json ()
>       (ht:Prin *JsonCallback "({x: 11, y: 22, z: 33});") )
> .. then I've verified that I actually get the object {x: 11, y: 22, 
> z: 33} back in my JavaScript. I'll try to make a small demo during 
> the weekend.

That's basically the right way, I think.

> As you may see from the above lines, I used a global variable 
> *JsonCallback. I'd prefer my function json to use an input parameter 
> instead, and from app.html#urlSyntax I get the impression that that 
> should be possible. ("All arguments following the question mark are 
> passed to that function.") I haven't figured out how to do that yet.

Yes. If you omit the global, and separate the arguments with '&'


then you could define 'json' as

   (de json (Str1 Str2)
      .. )

You can also encode numbers, internal+external symbols, and simple
lists, if you use 'ht:Fmt' (or 'mkUrl').

   : (pack "http://localhost:8080/@json?"; (ht:Fmt 123 'abc (4 5 6)))
   -> "http://localhost:8080/@json?+123&$abc&_+4_+5_+6";

Then 'json' will receive a number, an internal symbol, and a list of

Also, I would recommend not just to print the results, but also send
along a proper HTTP header, and take care of the chunked transfer. This
can be done this way:

   (de json @
      (httpHead "text/plain; charset=utf-8")
      (ht:Out T (ht:Prin ...)) )

I'm not sure how the *JsonCallback should work, though.

- Alex

Reply via email to