json-alias
Version, currently main branch1 version
- main branchlatestFeb 17, 2023
github.com/nobodywasishere/json-alias
Macro for generating an alias type from JSON/YAML
0 stars
0 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
json-alias:
github: nobodywasishere/json-alias
branch: mainmain is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
1.7.2- License
- MIT
- Author
- Margret Riegert
- Target
parse_datafrom src/json-alias/parse_data.cr
Dependencies
This version declares no dependencies.
README
JSON::Alias
Macro for generating an alias type from JSON/YAML. Useful for parsing JSON/YAML without needing to manually create a type alias or parse by hand.
Installation
-
Add the dependency to your
shard.yml:dependencies: json-alias: github: nobodywasishere/json-alias -
Run
shards install
Usage
Generate an alias from a JSON/YAML file at compile time:
require "json"
require "json-alias"
class TestClass
# alias JsonData = Array(Hash(String, Int32 | String) | Hash(String, Int32) | Hash(String, String))
# Need to pass absolute path to example, hence __DIR__
JSON::Alias.from_json JsonData, "#{__DIR__}/example.json"
# alias YamlData = Array(Hash(String, Int32 | String) | Hash(String, Int32) | Hash(String, String))
JSON::Alias.from_yaml YamlData, "#{__DIR__}/example.yaml"
getter json : JsonData
getter yaml : YamlData
def initialize
data = File.read("#{__DIR__}/data.json")
@json = JsonData.from_json(data)
@yaml = YamlData.from_json(data)
end
end
tc = TestClass.new
puts tc.json
puts tc.yaml
puts "Success."
Tool for generating type from command-line:
$ shards build parse_data --release
$ ./bin/parse_data --file spec/example.json --type json
Array(Hash(String, Int32 | String) | Hash(String, Int32) | Hash(String, String))
Development
TODO: Write development instructions here
Contributing
- Fork it (https://github.com/nobodywasishere/json-alias/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Margret Riegert - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
main- Seen
- Feb 17, 2023
- Crystal
1.7.2- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/nobodywasishere/json-alias
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 17, 2026
- Synced
- Aug 17, 2026
- Versions
- 1