Skip to content

About

Transit for Jolt

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

transit-jolt

Transit (JSON encoding) for the Jolt Clojure runtime (Chez Scheme host). Implements the Transit 0.8 wire format.

Dependency

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.

Usage

(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.

Type mapping

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 -> the ratio extension transit-clj uses, ["~#ratio",["~n1","~n3"]], read back as a Ratio.
  • bytes (~b) -> byte array, written as base64.
  • time -> value for which inst? is true.
  • uuid -> value for which uuid? 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.

Tests

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 --init

Then run the suite with jolt on your PATH:

jolt -M:test

Set 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.

License

Apache License, Version 2.0. See LICENSE. Based on transit-cljs.

About

Transit for Jolt

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages