[cl-json-devel] Slot name with digits raise condition UNBOUND-SLOT
Boris Smilga
boris.smilga at gmail.com
Tue Jan 22 18:37:13 UTC 2013
On 22 Jan 2013, at 11:28, Олег wrote:
> (json:with-decoder-simple-clos-semantics
> (let ((json:*json-symbols-package* nil))
> (let ((x (json:decode-json-from-string
> "{\"foo1\": [1, 2, 3], \"bar1\": true,
> \"baz1\": \"!\"}")))
> (with-slots (foo1 bar1 baz1) x
> (values x foo1 bar1 baz1)))))
>
>
> The slot FOO1 is unbound in the object #<#<JSON:FLUID-CLASS NIL
> {1004085F33}>
> {1003CAFB43}>.
> [Condition of type UNBOUND-SLOT]
>
When Lisp slot names are derived from JSON object keys, they are
transcribed to more Lisp-like conventions: camel case is replaced
with hyphenation, all caps become framing asterisks, etc. So, slot
names in your Lisp code should be written with hyphens:
(json:with-decoder-simple-clos-semantics
(let ((json:*json-symbols-package* nil))
(let ((x (json:decode-json-from-string
"{\"foo1\": [1, 2, 3], \"bar1\": true,
\"baz1\": \"!\"}")))
(with-slots (foo-1 bar-1 baz-1) x
(values x foo-1 bar-1 baz-1)))))
=> #<#<JSON:FLUID-CLASS NIL {5D03A341}> {5A1ECF11}>
=> #(1 2 3)
=> T
=>"!"
If this disagrees too much with the conventions of your code, you can
change the way identifiers are transcribed by setting / rebinding the
variable *JSON-IDENTIFIER-NAME-TO-LISP* to the appropriate
transcriber function.
Hope this helps.
— B. Smilga.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cl-json-devel/attachments/20130122/c4edec97/attachment.html>
More information about the cl-json-devel
mailing list