j.j. bug

Hi,

I found a bug in .j.j:

correct:

.j.j “a"b”

“"a\"b"”

wrong:

.j.j `$“a"b”

“"a"b"”

the " is not escaped properly when encoding symbols.

Markus

And is this another one?

q) k:([a]b)

q) `k insert(1;2)

,0

q) .j.j k

“{{"a":1}:{"b":2}}”

This is not json, JSON.parse throws exception.

Are you supposed to use some other function for keyed tables?

you can use

.j.j 0!k

“[{"a":1,"b":1}]”

to make it unkeyed table. 

The other problem with these non-JSON outputs of .j.j is that .j.k doesn’t restore them to their original values, either.

I would have preferred to have a fix for .j.j. But given that .j.j code is simply beyond comprehension for me at this stage, this should do it for now. Thanks.

this wont be possbile to implement as json is not as powerful as the k datastructure. For example json can’t distinguish between symbol and string.

Try this: http://code.kx.com/wsvn/code/contrib/zuoqianxu/qgooglechart/json.q

In theory its possible if .j.j includes meta data in output and .j.k recognizes it on the way back.

The json.q library I referred to earlier handles keyed tables by making two key and value objects in the output.

for all interested, i think i wrote a successful patch for my above issue:
here the new .j code

J:(($01)!$falsetrue;s;{$[#x;x;“null”]};s;j;{s@[x;&“.”=8#x;:;“-”]};s)1 2 5 10 11 12 16h bin

j:{$[10=abs t:@x;s@,/{$[x in r:“\t\n\r"\”;“\”,“tnr"\“r?x;x]}'x;99=t;”{”,(“,”/:(j’!x),‘“:”,‘j’. x),“}”;-1<t;“[”,($[98=t;“,\n “;”,”]/:.Q.fc[j’]x),“]”;J[-t]@$x]}

c:{$[“{”=*x;($c'n#'x)!c'(1+n:x?'":")_'x:d x;"["=*x;.Q.fc[c']d x;q=*x;$[1\<+/v x;'err;“”,. x];“a”>*x;“F”$x;“n”=*x;0n;“t”=*x]}

k:{c x@&~v&x in" \t\n\r"};v:{=~(“\”=-1_q,x)<q=x};d:{$[1<n:(s:+\1 -1 1 -1"{}“?x)?0;1_'(0,&(v&”,"=x)&1=n#s)_x:n#x;()]}

i just patched the J function which transforms a given string (second param) of specified type (first param). I rewrote it to use the string function instead of a simple bracket enclosing.