package

github.com/j8r/dynany

0.2.2 / published May 16, 2019 / repository

Dynamic JSON/YAML/CON mapping manipulation - extends Any

Build Status

Dynany

Dynamic JSON/YAML/CON mapping manipulation - extends Any

Installation

Add the dependency to your shard.yml:

dependencies:
  dynany:
    github: j8r/dynany

Usage

This shard monkey patch JSON::Any, YAML::Any and CON::Any to extend them by adding this following methods, which are equivalent for those fround in Hash and Array.

The main difference is the argument, which accept an Enumerable which represents a path in the document.

The available methods are:

#[](path : Enunerable)

#[]?(path : Enumerable

#[]=(path : Enumerable)

#delete(path : Enumerable)

Example

require "dynany/json"

json = JSON.parse %({"hash": {"array": ["first", "second"]}})
json[["hash", "array", 1]]       # => "second"
json.delete ["hash", "array", 1] # => {"hash" => {"array" => ["first"]}}
json[["hash", "array", 1]]?      # => nil

License

Copyright (c) 2018-2019 Julien Reichardt - ISC License

API

  • CON
  • Dynany(T)
  • JSON

    The JSON module allows parsing and generating JSON documents.

  • YAML

    The YAML module provides serialization and deserialization of YAML version 1.1 to/from native Crystal data structures, with the additional independent types specified in http://yaml.org/type/