Liking cljdoc? Tell your friends :D

transit-clj

Transit is a data format and a set of libraries for conveying values between applications written in different languages. This library provides support for marshalling Transit data to/from Clojure.

This implementation's major.minor version number corresponds to the version of the Transit specification it supports.

NOTE: Transit is a work in progress and may evolve based on feedback. As a result, while Transit is a great option for transferring data between applications, it should not yet be used for storing data durably over time. This recommendation will change when the specification is complete.

Releases and Dependency Information

Maven dependency information:

<dependency>
  <groupId>com.cognitect</groupId>
  <artifactId>transit-clj</artifactId>
  <version>0.8.309</version>
</dependency>

Leiningen dependency information:

[com.cognitect/transit-clj "0.8.309"]

Usage

(require '[cognitect.transit :as transit])
(import [java.io ByteArrayInputStream ByteArrayOutputStream])

;; Write data to a stream
(def out (ByteArrayOutputStream. 4096))
(def writer (transit/writer out :json))
(transit/write writer "foo")
(transit/write writer {:a [1 2]})

;; Take a peek at the JSON
(.toString out)
;; => "{\"~#'\":\"foo\"} [\"^ \",\"~:a\",[1,2]]"

;; Read data from a stream
(def in (ByteArrayInputStream. (.toByteArray out)))
(def reader (transit/reader in :json))
(prn (transit/read reader))  ;; => "foo"
(prn (transit/read reader))  ;; => {:a [1 2]}

Default Type Mapping

Transit typeWrite acceptsRead returns
nullnilnil
stringjava.lang.Stringjava.lang.String
booleanjava.lang.Booleanjava.lang.Boolean
integerjava.lang.Byte, java.lang.Short, java.lang.Integer, java.lang.Longjava.lang.Long
decimaljava.lang.Float, java.lang.Doublejava.lang.Double
keywordclojure.lang.Keywordclojure.lang.Keyword
symbolclojure.lang.Symbolclojure.lang.Symbol
big decimaljava.math.BigDecimaljava.math.BigDecimal
big integerclojure.lang.BigInt,java.math.BigIntegerclojure.lang.BigInt
timejava.util.Datejava.util.Date
urijava.net.URI, com.cognitect.transit.URIcom.cognitect.transit.URI
uuidjava.util.UUIDjava.util.UUID
charjava.lang.Characterjava.lang.Character
arrayclojure.lang.IPersistentVector, java.util.Listclojure.lang.IPersistentVector
listclojure.lang.ISeqclojure.lang.ISeq
setclojure.lang.IPersistentSet,java.util.Setclojure.lang.IPersistentSet
mapclojure.lang.IPersistentMap,java.util.Mapclojure.lang.IPersistentMap
linkcognitect.transit.Linkcognitect.transit.Link
ratio +clojure.lang.Ratioclojure.lang.Ratio

+ Extension using tagged values

Contributing

This library is open source, developed internally by Cognitect. We welcome discussions of potential problems and enhancement suggestions on the transit-format mailing list. Issues can be filed using GitHub issues for this project. Because transit is incorporated into products and client projects, we prefer to do development internally and are not accepting pull requests or patches.

Copyright and License

Copyright © 2014 Cognitect

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Can you improve this documentation? These fine people already did:
David Chelimsky, Brenton Ashworth, puredanger, Tim Ewald, Alex Miller, dnolen, Bobby Calderwood & Russ Olsen
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close