# j.j. bug

**URL:** <https://forum.kx.com/t/j-j-bug/9295>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [December 12, 2014, 12:56pm UTC](https://forum.kx.com/t/j-j-bug/9295 "2014-12-12T12:56:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sieber](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@sieber](https://forum.kx.com/u/sieber)\
**Post date:** [December 12, 2014, 12:56pm UTC](https://forum.kx.com/t/j-j-bug/9295/1 "2014-12-12T12:56:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![borota](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@borota](https://forum.kx.com/u/borota)\
**Post date:** [December 12, 2014, 2:46pm UTC](https://forum.kx.com/t/j-j-bug/9295/2 "2014-12-12T14:46:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sieber](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@sieber](https://forum.kx.com/u/sieber)\
**Post date:** [December 12, 2014, 3:44pm UTC](https://forum.kx.com/t/j-j-bug/9295/3 "2014-12-12T15:44:00Z")

</div>

you can use

.j.j 0!k

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

to make it unkeyed table.&nbsp;

---

<div class="post-metadata">

**Author:** ![josh\_helzer](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@josh\_helzer](https://forum.kx.com/u/josh_helzer)\
**Post date:** [December 12, 2014, 9:03pm UTC](https://forum.kx.com/t/j-j-bug/9295/4 "2014-12-12T21:03:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![borota](https://avatars.discourse-cdn.com/v4/letter/b/f17d59/32.png) [@borota](https://forum.kx.com/u/borota)\
**Post date:** [December 13, 2014, 2:28am UTC](https://forum.kx.com/t/j-j-bug/9295/5 "2014-12-13T02:28:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sieber\_m1](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@sieber\_m1](https://forum.kx.com/u/sieber_m1)\
**Post date:** [December 13, 2014, 11:38am UTC](https://forum.kx.com/t/j-j-bug/9295/6 "2014-12-13T11:38:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rohit\_Tripathi](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@Rohit\_Tripathi](https://forum.kx.com/u/Rohit_Tripathi)\
**Post date:** [December 13, 2014, 12:55pm UTC](https://forum.kx.com/t/j-j-bug/9295/7 "2014-12-13T12:55:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rohit\_Tripathi](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@Rohit\_Tripathi](https://forum.kx.com/u/Rohit_Tripathi)\
**Post date:** [December 13, 2014, 10:05pm UTC](https://forum.kx.com/t/j-j-bug/9295/8 "2014-12-13T22:05:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sieber](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@sieber](https://forum.kx.com/u/sieber)\
**Post date:** [February 23, 2015, 2:37pm UTC](https://forum.kx.com/t/j-j-bug/9295/9 "2015-02-23T14:37:00Z")

</div>

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

J:(($`0`1)!$`false`true;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.
