JSON encoding and decoding function construction with support for configurable key conversion.
Supports:
Includes convenience coders for wire (i.e., service to service) JSON and database JSON:
For wire JSON:
For database JSON:
Add the following to your project.clj
file:
[io.logicblocks/jason "1.0.0"]
(require '[jason.core :refer [defcoders] :as jason])
(require '[camel-snake-kebab.core :refer [->snake_case_string
->snake_case_keyword]])
(defcoders standard)
(defcoders db
:encode-key-fn (jason/->encode-key-fn ->snake_case_string)
:decode-key-fn (jason/->decode-key-fn ->snake_case_keyword))
(->standard-json {:first-name "Jess"})
;; => "{\"first-name\": \"Jess\"}"
(->db-json {:first-name "Jess"})
;; => "{\"first_name\": \"Jess\"}"
(<-standard-json "{\"firstName\": \"Jess\"}")
;; => {"firstName" "Jess"}
(<-db-json "{\"first_name\": \"Jess\"}")
;; => {:first_name "Jess"}
See the Getting Started guide for more details.
Copyright © 2023 LogicBlocks Maintainers
Distributed under the terms of the MIT License.
Can you improve this documentation? These fine people already did:
Toby Clemson & Corin ChaplinEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close