3 ms·
This just works: USER> (yason:parse "{\"null\" : null, \"false\" : false, \"empty\": []}" :object-as :plist :
by junke 6y ago
This just works:
USER> (yason:parse "{\"null\" : null, \"false\" : false, \"empty\": []}"
:object-as :plist
:json-arrays-as-vectors t
:json-booleans-as-symbols t
:json-nulls-as-keyword t)
("null" :NULL "false" YASON:FALSE "empty" #())
Null is mapped to the :null keyword, false to a symbol named false in the yason package, and the empty vector to an empty lisp vector (in Lisp #(1 2 3) denotes a vector, whereas (1 2 3) is a linked-list). All threes can be distguinshed from the others.
All those options defaults to special (dynamically scoped) variables, so you don't have to pass them everytime.
Encoding prints to the standard output (you can redirect it to an http stream, if you want), so you don't see double-quotes being escaped, but the string is equivalent (modulo spaces):
USER> (yason:encode-plist *)
{"null":null,"false":false,"empty":[]}
The defaults in Yason just returns list for vectors, and map both null and false to nil, but this is not a problem: if you expect your field "items" to be a vector, then nil will denote the empty list, if you expect another field "enable-debug" to be a boolean, nil be good enough too. But in cases where you need to handle them differently, the library can help you distinguish among all kinds of value.
See https://phmarek.github.io/yason/ https://phmarek.github.io/yason/