magicjson

Version, currently master branch1 version
  • master branchlatestDec 2, 2017

github.com/calebuharrison/magicjson

No description declared in shard.yml.

0 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  magicjson:
    github: calebuharrison/magicjson
    branch: master

master is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
0.22.0
License
MIT
Author
Zatherz

Dependencies

This version declares no dependencies.

README

MagicJSON

A compiletime JSON parser generator for Crystal.

The main purpose that MagicJSON is supposed to fulfill is to make working with payloads that need external Crystal data (i.e. objects not in the payload that need to be passed all the way from from_json to an instance variable) painless, or at least much less painful than with the builtin JSON.mapping.

MagicJSON also supports inheritance and mixins naturally. You can, for example, have a class that defines a field, a module that defines another field and another module that defines yet another field. If you extend that class and include both modules in another class you will have 3 fields.

Installation

Add this to your application's shard.yml:

dependencies:
  magicjson:
    gitlab: zatherz/magicjson

Usage

require "magicjson"

Define a User with a username and a bot? field:

require "magicjson"

struct User
  include MagicJSON

  json_defaults getter: true # MagicJSON supports customizable defaults!
  field username : String
  field bot? : Bool = true, key: "bot" # As opposed to JSON.mapping, you can also easily define fields ending in question marks or exclamation marks.
end

Examples

A couple of examples are available in the examples/ directory.

Documentation

Read the documentation online or build it with crystal docs.

Contributors