pjson api

23 views
Skip to first unread message

Thomas McGuire

unread,
Sep 20, 2025, 12:38:29 AMSep 20
to fo...@jsoftware.com
convert/pjson doesn’t handle encoding of boolean properly

the decode function does convert to the appropriate datatype in J

So for the simple json object

dec_pjson_ '{"bool":true}'

┌────┬─┐

│bool│1│

└────┴─┘


We can check the datatype of the 1 and see that decode made it a boolean datatype.


datatype each dec_pjson_ '{"bool":true}'

┌───────┬───────┐

│literal│boolean│

└───────┴───────┘


However when encoding that json object from the decode it leaves it as an integer 1


enc_pjson_ dec_pjson_ '{"bool":true}'

{

"bool":1

}


I didn’t see the code for this on the jsoftware site. Chris Burke has a version of this and it seems in the “enc” verb there just needs to be a function “isbool” patterned after “isfloat” and then added to the case statement where the datatypes are processed


isfloat=: 8=3!:0

isbool=: 1=3!:0


.

.

.


if. 1<#$y do. if. isboxed y do. enc_dict y else. bk sep <@enc"_1 y end. elseif. isboxed y do. bk sep enc each y elseif. ischar y do. if. ESS = {. y do. }. y return. end. enc_char y elseif. isfloat y do. enc_num y elseif. isbool y do.

if. y do. 

'true'

else. 

'false'

end. elseif. do. enc_int y end.


I changed my local copy of pjson.ijs and it seems to work.


I didn’t see where this code was on the JSoftare Git site and I’ve never messed with the repository directly


Tom McGuire

chris burke

unread,
Sep 21, 2025, 1:19:12 PMSep 21
to fo...@jsoftware.com
Thanks for pointing this out. The addon has been updated to support
booleans, e.g.

load'convert/pjson'

enc_pjson_ 0 1 0 1
[false,true,false,true]

dec_pjson_ enc_pjson_ 0 1 0 1
0 1 0 1

The repo is on my personal github account. The wiki page has been
updated for this and the support for booleans, see
https://code.jsoftware.com/wiki/Addons/convert/pjson
Reply all
Reply to author
Forward
0 new messages