Skip to content
forked from metosin/jsonista

Clojure library for fast JSON encoding and decoding.

Notifications You must be signed in to change notification settings

yogthos/jsonista

 
 

Repository files navigation

jsonista Continuous Integration status

jsonissa / jsonista / jsoniin, jsonilla / jsonilta / jsonille

Clojure library for fast JSON encoding and decoding.

  • Explicit configuration
  • Embrace Java for speed
  • Uses Jackson directly
  • API docs

Aiming to be faster than Cheshire while still having all the necessary features for web development. Designed for use with Muuntaja.

Blogged:

Latest version

Clojars Project

Quickstart

(require '[jsonista.core :as j])

(j/write-value-as-string {"hello" 1})
;; => "{\"hello\":1}"

(j/read-value *1)
;; => {"hello" 1}

More examples

Changing how map keys are encoded & decoded:

(defn reverse-string [s] (apply str (reverse s)))

(def mapper
  (j/object-mapper 
    {:encode-key-fn (comp reverse-string name)
     :decode-key-fn (comp keyword reverse-string)}))

(-> {:kikka "kukka"} 
    (doto prn) 
    (j/write-value-as-string mapper) 
    (doto prn) 
    (j/read-value mapper)
    (prn))
; {:kikka "kukka"}
; "{\"akkik\":\"kukka\"}"
; {:kikka "kukka"}

Reading & writing directly into a file:

(def file (java.io.File. "hello.json"))

(j/write-value file {"hello" "world"})

(slurp file)
;; => "{\"hello\":\"world\"}"

(j/read-value file)
;; => {"hello" "world"}

Performance

  • All standard encoders and decoders are written in Java
  • Protocol dispatch with read-value & write-value
  • Jackson ObjectMapper is used directly
  • Small functions to support JVM Inlining

See perf-tests for details.

encode

decode

License

Copyright © 2016-2017 Metosin Oy.

Distributed under the Eclipse Public License, the same as Clojure.

About

Clojure library for fast JSON encoding and decoding.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Clojure 71.9%
  • Java 25.6%
  • Shell 2.5%