Advertisement
skidd0

Untitled

Jun 24th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. ;; CL-JSON seems inconsistent. Their docs say Alists convert to Objects and vice versa..
  2. ;; But, this does not seem to be the case with nested alists.
  3.  
  4. (setf *lst*
  5. '((:customers
  6. ((:first-name . "Tim") (:last-name . "B"))
  7. ((:first-name . "Tim") (:last-name . "B")))
  8. (:others
  9. ((:first-name . "Bill") (:last-name . "Hicks"))
  10. ((:first-name . "Bill") (:last-name . "Hicks")))))
  11. (json:encode-json *lst*)
  12. ;; prints:
  13. [
  14. [
  15. "customers",
  16. {"firstName":"Tim","lastName":"B"},
  17. {"firstName":"Tim","lastName":"B"}
  18. ],
  19. [
  20. "others",
  21. {"firstName":"Bill","lastName":"Hicks"},
  22. {"firstName":"Bill","lastName":"Hicks"}
  23. ]
  24. ]
  25. ;; The first level alist items (customers and others) are converted to arrays, not objects.
  26.  
  27. ;; However, when I try to decode json of the ideal form to lisp alists, it works as expected:
  28. (json:decode-json-from-string
  29. "{
  30. \"customers\": [
  31. {\"name\": \"Tim\"},
  32. {\"name\": \"Bob\"}
  33. ],
  34. \"other\": [
  35. {\"name\": \"Tim\"},
  36. {\"name\": \"Bob\"}
  37. ]
  38. }")
  39. ;; prints:
  40. ((:CUSTOMERS ((:NAME . "Tim")) ((:NAME . "Bob")))
  41. (:OTHER ((:NAME . "Tim")) ((:NAME . "Bob"))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement