https://github.com/j8r/dynany
Dynamic JSON/YAML mapping manipulation - extends Any
https://github.com/j8r/dynany
crystal
Last synced: 8 months ago
JSON representation
Dynamic JSON/YAML mapping manipulation - extends Any
- Host: GitHub
- URL: https://github.com/j8r/dynany
- Owner: j8r
- License: isc
- Created: 2018-07-22T12:42:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-16T08:48:21.000Z (almost 7 years ago)
- Last Synced: 2025-03-27T15:53:41.465Z (12 months ago)
- Topics: crystal
- Language: Crystal
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://cloud.drone.io/j8r/dynany)
# Dynany
Dynamic JSON/YAML/CON mapping manipulation - extends `Any`
## Installation
Add the dependency to your `shard.yml`:
```yaml
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](https://crystal-lang.org/api/master/Hash.html) and [Array](https://crystal-lang.org/api/master/array.html).
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
```crystal
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