Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; CL-JSON seems inconsistent. Their docs say Alists convert to Objects and vice versa..
- ;; But, this does not seem to be the case with nested alists.
- (setf *lst*
- '((:customers
- ((:first-name . "Tim") (:last-name . "B"))
- ((:first-name . "Tim") (:last-name . "B")))
- (:others
- ((:first-name . "Bill") (:last-name . "Hicks"))
- ((:first-name . "Bill") (:last-name . "Hicks")))))
- (json:encode-json *lst*)
- ;; prints:
- [
- [
- "customers",
- {"firstName":"Tim","lastName":"B"},
- {"firstName":"Tim","lastName":"B"}
- ],
- [
- "others",
- {"firstName":"Bill","lastName":"Hicks"},
- {"firstName":"Bill","lastName":"Hicks"}
- ]
- ]
- ;; The first level alist items (customers and others) are converted to arrays, not objects.
- ;; However, when I try to decode json of the ideal form to lisp alists, it works as expected:
- (json:decode-json-from-string
- "{
- \"customers\": [
- {\"name\": \"Tim\"},
- {\"name\": \"Bob\"}
- ],
- \"other\": [
- {\"name\": \"Tim\"},
- {\"name\": \"Bob\"}
- ]
- }")
- ;; prints:
- ((:CUSTOMERS ((:NAME . "Tim")) ((:NAME . "Bob")))
- (:OTHER ((:NAME . "Tim")) ((:NAME . "Bob"))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement