hankhero / cl-json

Json encoder and decoder for Common-Lisp
Other
76 stars 39 forks source link

How to get a value of false (as opposed to "false") #18

Closed ckonstanski closed 7 years ago

ckonstanski commented 8 years ago

I can get (encode-json) to emit a value of true quite easily: just use t. But I cannot figure out how to get a value of false.

I'm not talking about the strings "true" and "false". I'm talking about the javascript keywords true and false.

I tried (cl-json:json-bool nil). This gives me ["false"]. I also tried (cl-json:json-bool :false). It gives me ["true"].

What is the trick to getting false into my JSON?

martinflack commented 7 years ago

I notice that the explicit encoder can do it, although you then must use explicit data structures all through:

* (in-package :cl-json)
#<PACKAGE "JSON">
* (with-explicit-encoder (encode-json-to-string `(:alist . ((:yes . ,(json-bool t)) (:no . ,(json-bool nil))))))
"{\"yes\":true,\"no\":false}"

Take a look at (DESCRIBE 'ENCODE-JSON) under the method that accepts a list, for information on the explicit encoder.

ckonstanski commented 7 years ago

Got this solution incorporated into my code. It works! Thanks.