Rick Anaconda
Rick Anaconda

Reputation: 65

cl-json decode-json getting plist keys as strings, not as symbols

I am trying to decode json data in Common Lisp using the library cl-json. But I have a problem : when using the decode-json-from-string function, with this data, for example

{"Hello": "world"}

I get a plist that looks like this:

(:*HELLO . "world")

But I want the accessor to be a symbol, not a string.

Upvotes: 1

Views: 221

Answers (1)

user5920214
user5920214

Reputation:

:*HELLO is a symbol: it's a symbol in the keyword package. How symbols are turned to and from JSON object keys is described in the manual: the default encode and decoders map object keys onto symbols, doing a lot of fancy camel-case translation. *json-identifier-name-to-lisp* & *lisp-identifier-name-to-json* are two variables which hold the default mapping functions, which are camel-case-to-lisp and lisp-to-camel-case respectively. *json-symbols-package* controls the package where interning happens.

You can adjust any or all of these to do what you want.

Upvotes: 3

Related Questions