All Projects → tjson → Tjson.rb

tjson / Tjson.rb

Licence: mit
Ruby implementation of TJSON

Programming Languages

ruby
36898 projects - #4 most used programming language
types
53 projects

Projects that are alternatives of or similar to Tjson.rb

Kryo
Java binary serialization and cloning: fast, efficient, automatic
Stars: ✭ 5,247 (+23750%)
Mutual labels:  serialization
Marshmallow
A lightweight library for converting complex objects to and from simple Python datatypes.
Stars: ✭ 5,857 (+26522.73%)
Mutual labels:  serialization
Rust Crdt
a collection of well-tested, serializable CRDTs for Rust
Stars: ✭ 747 (+3295.45%)
Mutual labels:  serialization
Msgpack Rust
MessagePack implementation for Rust / msgpack.org[Rust]
Stars: ✭ 561 (+2450%)
Mutual labels:  serialization
Bridge Deprecated
[DEPRECATED]: Prefer Retrofit/OkHttp by Square, or Fuel for Kotlin
Stars: ✭ 624 (+2736.36%)
Mutual labels:  serialization
Reservoir
Android library to easily serialize and cache your objects to disk using key/value pairs.
Stars: ✭ 674 (+2963.64%)
Mutual labels:  serialization
Fastjson
A fast JSON parser/generator for Java.
Stars: ✭ 23,997 (+108977.27%)
Mutual labels:  serialization
Strictyaml
Type-safe YAML parser and validator.
Stars: ✭ 836 (+3700%)
Mutual labels:  serialization
Rkyv
Zero-copy deserialization framework for Rust
Stars: ✭ 590 (+2581.82%)
Mutual labels:  serialization
Iod
Meta programming utilities for C++14. Merged in matt-42/lithium
Stars: ✭ 731 (+3222.73%)
Mutual labels:  serialization
Avro4s
Avro schema generation and serialization / deserialization for Scala
Stars: ✭ 593 (+2595.45%)
Mutual labels:  serialization
Pbf
A low-level, lightweight protocol buffers implementation in JavaScript.
Stars: ✭ 618 (+2709.09%)
Mutual labels:  serialization
Go Capnproto2
Cap'n Proto library and code generator for Go
Stars: ✭ 682 (+3000%)
Mutual labels:  serialization
Firely Net Sdk
The official Firely .NET SDK for HL7 FHIR
Stars: ✭ 560 (+2445.45%)
Mutual labels:  serialization
Msgpack Cli
MessagePack implementation for Common Language Infrastructure / msgpack.org[C#]
Stars: ✭ 761 (+3359.09%)
Mutual labels:  serialization
Fasteasymapping
A tool for fast serializing & deserializing of JSON
Stars: ✭ 556 (+2427.27%)
Mutual labels:  serialization
Bluecap
iOS Bluetooth LE framework
Stars: ✭ 669 (+2940.91%)
Mutual labels:  serialization
Protobuf Convert
Macros for convenient serialization of Rust data structures into/from Protocol Buffers 3
Stars: ✭ 22 (+0%)
Mutual labels:  serialization
Jackson Module Kotlin
Module that adds support for serialization/deserialization of Kotlin (http://kotlinlang.org) classes and data classes.
Stars: ✭ 830 (+3672.73%)
Mutual labels:  serialization
Awesome Django Rest Framework
💻😍Tools, processes and resources you need to create an awesome API with Django REST Framework
Stars: ✭ 689 (+3031.82%)
Mutual labels:  serialization

TJSON for Ruby Gem Version Build Status Code Climate MIT licensed

A Ruby implementation of TJSON: Tagged JSON with Rich Types.

TJSON is a microformat which supplements JSON with an extended set of data types by supplying a type "tag" embedded in object member names:

{
  "array-example:A<O>": [
    {
      "string-example:s": "foobar",
      "binary-data-example:d": "QklOQVJZ",
      "float-example:f": 0.42,
      "int-example:i": "42",
      "timestamp-example:t": "2016-11-06T22:27:34Z",
      "boolean-example:b": true
    }
  ],
  "set-example:S<i>": [1, 2, 3]
}

Help and Discussion

Have questions? Want to suggest a feature or change?

Requirements

This library is tested against the following Ruby versions:

  • 2.4
  • 2.5
  • 2.6
  • JRuby

Other Ruby versions may work, but are not officially supported.

Installation

Add this line to your application's Gemfile:

gem 'tjson'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tjson

API

TJSON.parse

To parse a TJSON document, use the TJSON.parse method:

>> TJSON.parse('{"foo:s":"bar"}')
=> {"foo"=>"bar"}

TJSON.generate

To generate TJSON from Ruby objects, use the TJSON.generate method:

puts TJSON.generate({"foo" => "bar"})
# {"foo:s:"bar"}

For better formatting, use the TJSON.pretty_generate method:

puts TJSON.pretty_generate({"array-example" => [{"string-example" => "foobar", "binary-example" => "BINARY".b, "float-example" => 0.42, "int-example" => 42, "timestamp-example" => Time.now}]})
# {
#   "array-example:A<O>": [
#     {
#       "string-example:s": "foobar",
#       "binary-example:d": "QklOQVJZ",
#       "float-example:f": 0.42,
#       "int-example:i": "42",
#       "timestamp-example:t": "2016-11-06T22:27:34Z"
#     }
#   ]
# }

Type Conversions

The table below shows how TJSON tags map to Ruby types:

Tag Ruby Type
b true or false
d String with Encoding::ASCII_8BIT (a.k.a. Encoding::BINARY)
f Float
i Integer (Fixnum or Bignum on Ruby <2.4 )
u Integer (Fixnum or Bignum on Ruby <2.4 )
s String with Encoding::UTF_8
t Time
A Array
O TJSON::Object (a subclass of ::Hash)
S Set

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tjson/tjson-ruby

License

Copyright (c) 2017 Tony Arcieri. Distributed under the MIT License. See LICENSE.txt for further details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].