All Projects → hyperloris → tyson

hyperloris / tyson

Licence: MIT license
A TypeScript serialization/deserialization library to convert objects to/from JSON

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to tyson

json struct
json_struct is a single header only C++ library for parsing JSON directly to C++ structs and vice versa
Stars: ✭ 279 (+1016%)
Mutual labels:  serialization, deserialization
NBT
A java implementation of the NBT protocol, including a way to implement custom tags.
Stars: ✭ 128 (+412%)
Mutual labels:  serialization, deserialization
sexp-grammar
Invertible parsing for S-expressions
Stars: ✭ 28 (+12%)
Mutual labels:  serialization, deserialization
marshmallow-validators
Use 3rd-party validators (e.g. from WTForms and colander) with marshmallow
Stars: ✭ 24 (-4%)
Mutual labels:  serialization, deserialization
CodableWrapper
@codec("encoder", "decoder") var cool: Bool = true
Stars: ✭ 143 (+472%)
Mutual labels:  serialization, deserialization
har-rs
A HTTP Archive format (HAR) serialization & deserialization library, written in Rust.
Stars: ✭ 25 (+0%)
Mutual labels:  serialization, deserialization
cattrs
Complex custom class converters for attrs.
Stars: ✭ 565 (+2160%)
Mutual labels:  serialization, deserialization
Jsonapi Rb
Efficiently produce and consume JSON API documents.
Stars: ✭ 219 (+776%)
Mutual labels:  serialization, deserialization
nason
🗜 Ultra tiny serializer / encoder with plugin-support. Useful to build binary files containing images, strings, numbers and more!
Stars: ✭ 30 (+20%)
Mutual labels:  serialization, deserialization
parco
🏇🏻 generalist, fast and tiny binary parser and compiler generator, powered by Go 1.18+ Generics
Stars: ✭ 57 (+128%)
Mutual labels:  serialization, deserialization
sqlathanor
Serialization / De-serialization support for the SQLAlchemy Declarative ORM
Stars: ✭ 105 (+320%)
Mutual labels:  serialization, deserialization
dataclasses-jsonschema
JSON schema generation from dataclasses
Stars: ✭ 145 (+480%)
Mutual labels:  serialization, deserialization
avro-serde-php
Avro Serialisation/Deserialisation (SerDe) library for PHP 7.3+ & 8.0 with a Symfony Serializer integration
Stars: ✭ 43 (+72%)
Mutual labels:  serialization, deserialization
bytes
Work with bytes and implement network protocols
Stars: ✭ 77 (+208%)
Mutual labels:  serialization, deserialization
Jsonapi Rails
Rails gem for fast jsonapi-compliant APIs.
Stars: ✭ 242 (+868%)
Mutual labels:  serialization, deserialization
serde
🚝 (unmaintained) A framework for defining, serializing, deserializing, and validating data structures
Stars: ✭ 49 (+96%)
Mutual labels:  serialization, deserialization
Mashumaro
Fast and well tested serialization framework on top of dataclasses
Stars: ✭ 208 (+732%)
Mutual labels:  serialization, deserialization
Schematics
Project documentation: https://schematics.readthedocs.io/en/latest/
Stars: ✭ 2,461 (+9744%)
Mutual labels:  serialization, deserialization
avrow
Avrow is a pure Rust implementation of the avro specification https://avro.apache.org/docs/current/spec.html with Serde support.
Stars: ✭ 27 (+8%)
Mutual labels:  serialization, deserialization
VSerializer
A library to serialize and deserialize objects with minimum memory usage.
Stars: ✭ 25 (+0%)
Mutual labels:  serialization, deserialization

Tyson is a TypeScript serialization/deserialization library to convert objects to/from JSON.

Features

  • Simple toJson() and fromJson() methods for conversions
  • Many options on the property (e.g. custom naming, required and more)
  • Type-safe JSON deserialization
  • Support for multi-type arrays
  • Custom conversions through adapters and factories

Installation

You can install tyson using npm:

npm install --save @hyperloris/tyson

Usage

The primary class to use is Tyson which you can just create by calling new Tyson(). There is also a class TysonBuilder available that can be used to create a Tyson instance with various settings (e.g. register a custom type adapter).

Requirements

There are three requirements to be met in order to make the library work properly:

  • Set experimentalDecorators and emitDecoratorMetadata to true on your tsconfig.json file
  • Properties need to be preceded by the @JsonProperty annotation
  • Properties need to have a default value (e.g. undefined)

A nice example

Let's start with a JSON representing a city:

{
  "name": "Bologna",
  "population": 388884,
  "monuments": ["Piazza Maggiore", "Palazzo Re Enzo"],
  "mayor": {
    "full_name": "Virginio Merola",
    "birthdate": "1955-02-14T00:00:00"
  }
}

Now we need a couple of TypeScript classes:

export class User {
  @JsonProperty("full_name")
  name: string = undefined;
  @JsonProperty({ type: Date })
  birthdate: Date = undefined;
}

export class City {
  @JsonProperty()
  name: string = undefined;
  @JsonProperty()
  population: number = undefined;
  @JsonProperty({ name: "monuments", type: [String] })
  private _monuments: string[] = undefined;
  @JsonProperty("mayor")
  private _mayor: User = undefined;
}

At this point we are ready to use the library:

const tyson = new Tyson();
const city = tyson.fromJson(json, City);
const json = tyson.toJson(city);

Documentation

Tyson API: generated with TypeDoc at every release.

Inspiration

The library is inspired by the Gson library.

License

MIT

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