On Thu, May 15, 2014 at 4:53 PM, Marshall Lochbaum <[email protected]>
wrote:
> JD has code to set up a server which receives JD queries and returns
> their results. We would like to support JSON output in addition to the
> serialized J and text formats which are currently supported.

I do not know enough about JD to understand what this means in terms of
JSON.

> Obviously sending only the first row of a result is no good, and sending
> json which is decoded into a bunch of boxes is quite inefficient.

Understood.

> It sounds like you (and possibly the creators of convert/json) have
> spent more time working with JSON data in J than the other way around.
> If the answer to my question is that the feature that I'm looking for
> doesn't currently exist, then that's still an answer and I will start
> working on modifying the convert/json code.

It's more that you can't have a "one size fits all" solution when you need
multiple sizes.

Looking at enc_json and J's three primary data types:

   enc:json 100+i.3 3
100
   $enc:json 100+i.3 3
3
   enc_json ":100+i.3 3
"100 101 102103 104 105106 107 108"
   enc_json ;:'this is a test'
["this","is","a","test"]
   enc_json <;:'this is a test'
[["this","is","a","test"]]

This matches your suggestion that it's more about reading json than
emitting J. So let's look at dec_json:

   dec_json '{"ab": 3, "def": [0,1,2]}'
┌──┬───────┐
│ab│def    │
├──┼───────┤
│3 │┌─┬─┬─┐│
│  ││0│1│2││
│  │└─┴─┴─┘│
└──┴───────┘

It looks like boxing individual numbers is exactly how it was designed, for
the case where you want to generate numeric arrays.

So I see two options for you:

(1) Translate your data to the format enc_json wants
(2) define your own system of mapping J to JSON and back

Here's what (1) might look like:
  jenc_json=: enc_json@(($ ,&<&(<"0^:(0={.@(0&#))) ,)L:0)

   jenc_json 3 2 1
[[3],[3,2,1]]
   jenc_json 3 2 1;4 3 2
[[[3],[3,2,1]],[[3],[4,3,2]]]
   jenc_json i. 3 3
[[3,3],[0,1,2,3,4,5,6,7,8]]

But decoding is going to be a bit of a mess unless you first constrain what
you are trying to accomplish (because now there are two ways of decoding
some otherwise legal json objects).

So I'd recommend you take some time to specify what it is that you want to
support. Obviously some JSON is going to be garbage for you. You need
someone to sit down and draw a line between the garbage JSON and the
supported JSON, or you're not going to get anywhere.

Thanks,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to