• Stars
    star
    384
  • Rank 111,726 (Top 3 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Clojure library for fast JSON encoding and decoding.

jsonista Continuous Integration status cljdoc badge

jsonissa / jsonista / jsoniin, jsonilla / jsonilta / jsonille

Clojure library for fast JSON encoding and decoding.

Faster than data.json or Cheshire while still having the necessary features for web development. Designed for use with Muuntaja.

Blogged:

Latest version

Clojars Project

Requires Java1.8+

Quickstart

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

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

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

Examples

Using explicit ObjectMapper:

(-> {:dog {:name "Teppo"}}
    (j/write-value-as-bytes j/default-object-mapper)
    (j/read-value j/default-object-mapper))
;; => {"dog" {"name" "Teppo"}}

Using keyword keys:

(-> {:dog {:name "Teppo"}}
    (j/write-value-as-bytes j/keyword-keys-object-mapper)
    (j/read-value j/keyword-keys-object-mapper))
;; => {:dog {:name "Teppo"}}

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"}

Adding support for joda-time Classes, used by clj-time.

;; [com.fasterxml.jackson.datatype/jackson-datatype-joda "2.9.5"]
(import '[com.fasterxml.jackson.datatype.joda JodaModule])
(import '[org.joda.time LocalDate])

(def mapper
  (j/object-mapper
    {:modules [(JodaModule.)]}))

(j/write-value-as-string (LocalDate. 0) mapper)
; "\"1970-01-01\""

Tagged JSON

Adding support for lossless encoding data using tagged values. This includes both reading and writing support.

(def mapper
  (j/object-mapper
    {:encode-key-fn true
     :decode-key-fn true
     :modules [(jt/module
                 {:handlers {Keyword {:tag "!kw"
                                      :encode jt/encode-keyword
                                      :decode keyword}
                             PersistentHashSet {:tag "!set"
                                                :encode jt/encode-collection
                                                :decode set}}})]}))

(-> {:system/status #{:status/good}}
    (j/write-value-as-string mapper)
    (doto prn)
    (j/read-value mapper))
; prints "{\"system/status\":[\"!set\",[[\"!kw\",\"status/good\"]]]}"
; => {:system/status #{:status/good}}

In simple perf tests, tagged JSON is much faster than EDN or Transit.

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

Measured using lein-jmh, see perf-tests for details.

Throughput, relative

encode

decode

Throughput, absolute

encode

decode

Throughput, data

➜  jsonista git:(master) ✗ lein jmh '{:file "benchmarks.edn", :type :quick, :format :table}'
{:% 100.0 :eta "00:00:00"}

:benchmark                     :name    :mode        :samples  :score              :score-error  :params
-----------------------------  -------  -----------  --------  ------------------  ------------  --------------
jsonista.jmh/encode-data-json  :encode  :throughput  5         2011809.137  ops/s  12600.809     {:size "10b"}
jsonista.jmh/encode-data-json  :encode  :throughput  5         382677.707   ops/s  2861.142      {:size "100b"}
jsonista.jmh/encode-data-json  :encode  :throughput  5         66403.631    ops/s  597.436       {:size "1k"}
jsonista.jmh/encode-data-json  :encode  :throughput  5         5480.185     ops/s  58.379        {:size "10k"}
jsonista.jmh/encode-data-json  :encode  :throughput  5         576.691      ops/s  15.682        {:size "100k"}
jsonista.jmh/encode-cheshire   :encode  :throughput  5         996875.314   ops/s  5688.227      {:size "10b"}
jsonista.jmh/encode-cheshire   :encode  :throughput  5         482130.613   ops/s  2685.181      {:size "100b"}
jsonista.jmh/encode-cheshire   :encode  :throughput  5         128936.005   ops/s  879.709       {:size "1k"}
jsonista.jmh/encode-cheshire   :encode  :throughput  5         12209.066    ops/s  94.285        {:size "10k"}
jsonista.jmh/encode-cheshire   :encode  :throughput  5         1258.157     ops/s  12.340        {:size "100k"}
jsonista.jmh/encode-jsonista   :encode  :throughput  5         6356105.348  ops/s  85360.100     {:size "10b"}
jsonista.jmh/encode-jsonista   :encode  :throughput  5         2010379.039  ops/s  67648.165     {:size "100b"}
jsonista.jmh/encode-jsonista   :encode  :throughput  5         409264.663   ops/s  3704.992      {:size "1k"}
jsonista.jmh/encode-jsonista   :encode  :throughput  5         34527.245    ops/s  251.065       {:size "10k"}
jsonista.jmh/encode-jsonista   :encode  :throughput  5         2934.595     ops/s  15.858        {:size "100k"}
jsonista.jmh/encode-jackson    :encode  :throughput  5         6275467.563  ops/s  123578.482    {:size "10b"}
jsonista.jmh/encode-jackson    :encode  :throughput  5         2092035.098  ops/s  11417.613     {:size "100b"}
jsonista.jmh/encode-jackson    :encode  :throughput  5         408380.251   ops/s  10912.350     {:size "1k"}
jsonista.jmh/encode-jackson    :encode  :throughput  5         31992.554    ops/s  230.781       {:size "10k"}
jsonista.jmh/encode-jackson    :encode  :throughput  5         2887.485     ops/s  12.491        {:size "100k"}
jsonista.jmh/decode-data-json  :decode  :throughput  5         2257552.949  ops/s  23890.443     {:size "10b"}
jsonista.jmh/decode-data-json  :decode  :throughput  5         498261.935   ops/s  2348.572      {:size "100b"}
jsonista.jmh/decode-data-json  :decode  :throughput  5         85191.855    ops/s  321.961       {:size "1k"}
jsonista.jmh/decode-data-json  :decode  :throughput  5         7763.264     ops/s  250.502       {:size "10k"}
jsonista.jmh/decode-data-json  :decode  :throughput  5         771.691      ops/s  6.559         {:size "100k"}
jsonista.jmh/decode-cheshire   :decode  :throughput  5         1099821.870  ops/s  14796.659     {:size "10b"}
jsonista.jmh/decode-cheshire   :decode  :throughput  5         544013.773   ops/s  4122.539      {:size "100b"}
jsonista.jmh/decode-cheshire   :decode  :throughput  5         109517.975   ops/s  911.623       {:size "1k"}
jsonista.jmh/decode-cheshire   :decode  :throughput  5         10017.553    ops/s  50.871        {:size "10k"}
jsonista.jmh/decode-cheshire   :decode  :throughput  5         1014.003     ops/s  18.609        {:size "100k"}
jsonista.jmh/decode-jsonista   :decode  :throughput  5         3476196.425  ops/s  21535.641     {:size "10b"}
jsonista.jmh/decode-jsonista   :decode  :throughput  5         792773.466   ops/s  8209.591      {:size "100b"}
jsonista.jmh/decode-jsonista   :decode  :throughput  5         160180.797   ops/s  554.940       {:size "1k"}
jsonista.jmh/decode-jsonista   :decode  :throughput  5         14151.302    ops/s  107.906       {:size "10k"}
jsonista.jmh/decode-jsonista   :decode  :throughput  5         1508.829     ops/s  5.855         {:size "100k"}
jsonista.jmh/decode-jackson    :decode  :throughput  5         5145394.434  ops/s  84237.662     {:size "10b"}
jsonista.jmh/decode-jackson    :decode  :throughput  5         1339393.911  ops/s  6660.176      {:size "100b"}
jsonista.jmh/decode-jackson    :decode  :throughput  5         274465.912   ops/s  1589.614      {:size "1k"}
jsonista.jmh/decode-jackson    :decode  :throughput  5         29607.044    ops/s  183.068       {:size "10k"}
jsonista.jmh/decode-jackson    :decode  :throughput  5         2539.491     ops/s  17.753        {:size "100k"}

Making a release

  • Update CHANGELOG.md and increment the version number in project.clj
  • Commit and push to Github
  • Create a Github release here
    • Use the version number of the release for the tag name
  • The Github Actions release workflow should fire and deploy a release to clojars

License

Copyright © 2016-2021 Metosin Oy.

Distributed under the Eclipse Public License 2.0.

More Repositories

1

malli

High-performance data-driven data specification library for Clojure/Script.
Clojure
1,499
star
2

reitit

A fast data-driven routing library for Clojure/Script
Clojure
1,313
star
3

spec-tools

Clojure(Script) tools for clojure.spec
Clojure
586
star
4

muuntaja

Clojure library for fast http api format negotiation, encoding and decoding.
Clojure
410
star
5

ring-swagger

Swagger Spec for Clojure Web Apps
Clojure
360
star
6

kekkonen

A remote (CQRS) API library for Clojure.
Clojure
220
star
7

tilakone

Minimalistic finite state machine (FSM) in Clojure
Clojure
192
star
8

sieppari

Small, fast, and complete interceptor library for Clojure/Script
Clojure
189
star
9

pohjavirta

Fast & Non-blocking Clojure wrapper for Undertow
Clojure
162
star
10

ring-http-response

Handling HTTP Statuses with Clojure(Script)
Clojure
139
star
11

schema-tools

Clojure(Script) tools for Plumatic Schema
Clojure
106
star
12

porsas

Experimental stuff for going fast with Clojure + JDBC & Async SQL
Clojure
95
star
13

talvi

Opinionated and Performant Web Application Stack for Clojure/Script
80
star
14

schema-viz

Plumatic Schema visualization using Graphviz.
Clojure
74
star
15

potpuri

Common clojure stuff.
Clojure
69
star
16

komponentit

Collection of bespoke Reagent components
Clojure
61
star
17

bat-test

Fast Clojure.test runner for Boot and Leiningen
Clojure
60
star
18

ring-swagger-ui

Swagger UI packaged for Ring Apps
Clojure
48
star
19

scjsv

Simple Clojure JSON-Schema Validator
Clojure
47
star
20

testit

Midje like assertions for Clojure.test
Clojure
43
star
21

compojure-api-examples

Compojure API example
Clojure
32
star
22

maailma

Opinionated environment variables library
Clojure
31
star
23

vega-tools

Utilities for working with Vega visualization grammar in ClojureScript.
Clojure
27
star
24

fnhouse-swagger

Swagger integration for fnhouse
Clojure
22
star
25

spec-swagger

Master Swagger2 & OpenAPI3 specs with Clojure(Script) & clojure.spec
Clojure
21
star
26

virhe

Beautiful Error Message for Clojure/Script
Clojure
20
star
27

reagent-dev-tools

Development tool panel for Reagent
Clojure
19
star
28

mallitaulut

Extract Malli schemas from SQL table schemas.
Clojure
17
star
29

eines

Simple Clojure and ClojureScript library for WebSocket communication
Clojure
16
star
30

sauna-todo

Simple full-stack TODO app example for demonstrating Clojure(script)
Clojure
16
star
31

packaging-clojure-examples

Packaging a full-stack Clojure web app for production
Clojure
16
star
32

loiste

Excellent Excel library
Clojure
16
star
33

clojure-bootcamp

Clojure
14
star
34

metosin-common

Random collection of various namespaces used in multiple Metosin projects
Clojure
13
star
35

viesti

Data-Driven Message Dispatcher for Clojure/Script
12
star
36

sormilla

Playing with Leap Motion and Parrot AR.Drone
Clojure
11
star
37

malli.io

Malli playground, https://malli.io
Clojure
11
star
38

lomakkeet

Proof of concept: Form library for Reagent
Clojure
11
star
39

c2

Demo about compojure-api2 stuff
Clojure
8
star
40

cloud-busting

Basis for using Terraform to manage application runtime in AWS
HCL
7
star
41

palikka

Opinionated component library
Clojure
7
star
42

tyylikas

Clojure linter and fixer
Clojure
6
star
43

oksa

Generate GraphQL queries using Clojure data structures.
Clojure
6
star
44

kekkonen-sample

Sample project With Kekkonen
Clojure
5
star
45

clojure-bootcamp-setup

Setup instructions for Metosin Clojure Bootcamp training
Clojure
5
star
46

web-schemas

Prismatic Schema extensions for the Web.
Clojure
5
star
47

compojure-intro

compojure-intro
Clojure
4
star
48

clj-suomi

A Clojure library designed to access Finnish code sets.
Clojure
4
star
49

lokit

Single dependency for logging on the JVM
Clojure
4
star
50

tom

Tom, a graph-based component library
Clojure
4
star
51

bootcamp-2019-04-08

Bootcamp 2019-04-08
Clojure
4
star
52

boot-deps-size

Boot task to check size of dependencies
Clojure
4
star
53

om-dev-tools

Clojure
4
star
54

compojure-api-template

Compojure Api Template
Clojure
4
star
55

bootcamp-2021-feb

Lessons and exercises for bootcamp in February 2021
Clojure
4
star
56

kekkonen-building-permit-example

a complex simulated real-life case example showcase project
Clojure
4
star
57

terraform-study-group

3
star
58

training-2023-05-32

Advanced Clojure training
Clojure
3
star
59

open-source

Home page for Metosin's open source development work
JavaScript
3
star
60

lein-simulflow

ABANDONED: Combine several lein auto tasks for leaner workflow.
Clojure
3
star
61

bootcamp-2018-03-15-sample-app

Sample app for bootcamp 2018-03-15
Clojure
3
star
62

linkit

Om.next + Kekkonen test
Clojure
3
star
63

clj-ai-meetup

Case Studies in AI for Clojure Tampere meetup
Clojure
3
star
64

bootcamp-2

Bootcamp 2
Clojure
2
star
65

bootcamp3

Refactored bootcamp
Clojure
2
star
66

clojure-koulutus-2023-01-24-esitehtavat

Clojure ja ClojureScript koulutus 2023-01-24 esitehtävät
Clojure
2
star
67

bootcamp-2018-05-04

Sample app for bootcamp at 2018-05-04
Clojure
2
star
68

clojure-bootcamp-20150130

Clojure Bootcamp 2015-01-30 for Affecto
Clojure
2
star
69

clojure-finland-2018-05-30-cljs-ws-demo

ClojureScript and WebSocket demo for Clojure Finland 2018-05-20 meetup
Clojure
2
star
70

juustometsae

vain käyttötarkoitus puuttuu
2
star
71

training-day-1

Example materials for first part of training
Clojure
2
star
72

2016-09-09-clojure-training

Material for 2016-09-09 intermediate Clojure training topics about Tooling and Workflow; and Full-stack apps
Clojure
2
star
73

postgres-tools

WIP Postgresql utilities
Clojure
2
star
74

boot-alt-http

Simple boot http server task to serve files from classpath.
Clojure
2
star
75

clojure-koulutus-2023-01-24

Koulutusmateriaali 2023-01-24 koulutukseen
Clojure
1
star
76

clojurebridge-intro

Intro project for ClojureBridge, in Finnish. Olkaa hyvä.
Clojure
1
star
77

clojure-bootcamp-intro

Bootcamp intro project
Clojure
1
star
78

reitit-example

Sample layout for reitit
Clojure
1
star
79

bootbook

BootBook :- Clojure Bootcamp book-store example
Clojure
1
star
80

docker-circle-convox

Dockerfile
1
star
81

docker-circle-lein

1
star
82

ks-example

Simple example project with clj and cljs
Clojure
1
star
83

rabbitmq-agent

Clojure
1
star
84

bootcamp-luminus-2021-feb

Luminus application for 2021 February bootcamp
Clojure
1
star
85

compojure-api-sample

Compojure-api sample project with Component
Clojure
1
star
86

2016-09-09-clojure-training-2

Material for 2016-09-09 intermediate Clojure training: perf, polymorfic, data, diy weblib
Clojure
1
star
87

clojurebridge-helsinki

Homepage for ClojureBridge Finland
CSS
1
star
88

bootcamp-20170314

Bootcamp example for 2017/03/14-16 bootcamp
Clojure
1
star
89

example-project

Clojure
1
star