Transit (JSON encoding) for the Jolt Clojure runtime (Chez Scheme host). Implements the Transit 0.8 wire format.
Add to your deps.edn (Jolt resolves the :git/sha; the :git/tag is for
reference):
{:deps {jolt-lang/transit-jolt
{:git/url "https://github.com/jolt-lang/transit-jolt"
:git/tag "v0.1.1"
:git/sha "543b75796b90e7bd74b93ac2f398feb7db2425eb"}}}It pulls org.clojure/data.json (the JSON reader/writer) transitively.
(ns example
(:require [jolt.transit :as t]))
(t/write {:name "transit" :tags #{:a :b}})
;; => "[\"^ \",\"~:name\",\"transit\",\"~:tags\",[\"~#set\",[\"~:b\",\"~:a\"]]]"
(t/read (t/write {:name "transit" :tags #{:a :b}}))
;; => {:name "transit" :tags #{:a :b}}The facade is two functions: (t/write value) returns a transit-JSON string,
(t/read string) decodes one. There are no reader/writer objects.
Jolt has no Java types, so read returns host-native values where possible and
small records where the host can't represent the Transit type directly:
- Transit
null,boolean,string,keyword,symbol-> the obvious native value. integer-> native number; a value too wide for a long reads as a BigInt.big integer(~n) -> native integer. Integers past 64 bits are written as~n.decimal-> native number; integer/decimal distinction is preserved on the wire.big decimal(~f) -> BigDecimal, and a BigDecimal is written as~f.ratio-> theratioextension transit-clj uses,["~#ratio",["~n1","~n3"]], read back as a Ratio.bytes(~b) -> byte array, written as base64.time-> value for whichinst?is true.uuid-> value for whichuuid?is true.uri->java.net.URI.char->jolt.transit.CharV(holds a 1-char string).array,list,set,map-> the matching Jolt collection.- Unknown tags ->
jolt.transit.TaggedValue(tag+value), re-emitted on write so non-conforming round-trips stay lossless.
The suite compares against golden exemplars from
transit-format, which is vendored
as a git submodule at transit-format/. Initialize it after cloning:
git clone --recurse-submodules https://github.com/jolt-lang/transit-jolt.git # or, for an existing clone:
git submodule update --initThen run the suite with jolt on your PATH:
jolt -M:testSet TRANSIT_FORMAT to point at a different transit-format checkout if needed.
The suite decodes every golden .json, checks the decode against its paired
.edn where Jolt can read it, and asserts read/write/read idempotency over the
whole exemplar corpus.
Apache License, Version 2.0. See LICENSE. Based on
transit-cljs.