No description, website, or topics provided.
Ruby Java Shell
Clone or download


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

API docs

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.


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.

Releases and Dependency Information



gem install transit-ruby

Basic Usage

# io can be any Ruby IO

writer =, io) # or :json-verbose, :msgpack

reader =, io) # or :msgpack

# or {|val| do_something_with(val)}

For example:

irb(2.1.1): io ='', 'w+')
==========> #<StringIO:0x007faab2ec3970>
irb(2.1.1): writer =, io)
==========> #<Transit::Writer:0x007faab2e8c1c8 @marshaler=#<Transit::JsonMarshaler:0x007faab2e1a168..........(snip)..........
irb(2.1.1): writer.write("abc")
==========> nil
irb(2.1.1): writer.write(123456789012345678901234567890)
==========> nil
irb(2.1.1): io.string
==========> "[\"~#'\",\"abc\"]\n[\"~#'\",\"~n123456789012345678901234567890\"]\n"
irb(2.1.1): reader =,
==========> #<Transit::Reader:0x007faab2db48e0 @reader=#<Transit::JsonUnmarshaler:0x007faab2dae030 @..........(snip)..........
irb(2.1.1): {|val| puts val}

Custom Handlers

Custom Write Handlers

Implement tag, rep(obj) and string_rep(obj) methods. For example:

Point =,:y) do
  def to_a; [x,y] end

class PointWriteHandler
  def tag(_) "point" end
  def rep(o) o.to_a  end
  def string_rep(_) nil end

Custom Read Handlers

Implement from_rep(rep) method. For example:

class PointReadHandler
  def from_rep(rep)*rep)

Example Usage

io ='', 'w+')
writer =, io,
                             :handlers => {Point =>})

p io.string.chomp
#=> "[\"~#point\",[37,42]]"

reader =,,
                             :handlers  => {"point" =>})
#=> #<struct Point x=37, y=42>

See Transit::WriteHandlers for more info.

Default Type Mapping

Transit type Write accepts Read returns Example(write) Example(read)
null nil nil nil nil
string String String "abc" "abc"
boolean true, false true, false false false
integer Integer Integer 123 123
decimal Float Float 123.456 123.456
keyword Symbol Symbol :abc :abc
symbol Transit::Symbol Transit::Symbol"foo") #<Transit::Symbol "foo">
big decimal BigDecimal BigDecimal"2**64") #<BigDecimal:7f9e6d33c558>
big integer Integer Integer 2**128 340282366920938463463374607431768211456
time DateTime, Date, Time DateTime #<DateTime: 2014-07-15T15:52:27+00:00 ((2456854j,57147s,23000000n),+0s,2299161j)>
uri Addressable::URI, URI Addressable::URI Addressable::URI.parse("") #<Addressable::URI:0x3fc0e20390d4 URI:>
uuid Transit::UUID Transit::UUID #<Transit::UUID "defa1cce-f70b-4ddb-bb6e-b6ac817d8bc8">
char Transit::TaggedValue String"c", "a") "a"
array Array Array [1, 2, 3] [1, 2, 3]
list Transit::TaggedValue Array"list", [1, 2, 3]) [1, 2, 3]
set Set Set[1, 2, 3]) #<Set: {1, 2, 3}>
map Hash Hash {a: 1, b: 2, c: 3} {:a=>1, :b=>2, :c=>3}
bytes Transit::ByteArray Transit::ByteArray"base64") base64
link Transit::Link Transit::Link""), "search") #<Transit::Link:0x007f81c405b7f0 @values={"href"=>#<Addressable::URI:0x3fc0e202dfb8 URI:>, "rel"=>"search", "name"=>nil, "render"=>nil, "prompt"=>nil}>

Additional types (not required by the transit-format spec)

Semantic type Write accepts Read returns Example(write) Example(read)
ratio Rational Rational Rational(1, 3) Rational(1, 3)

Tested Ruby Versions

  • MRI 2.1.10, 2.2.7, 2.3.4, 2.4.0, 2.4.1
  • JRuby 1.7.13..16

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

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.