jsonable
Jsonable
Json helper that will simplify common json outputs for objects. It can help you build and scaffold JSON APIs faster, by providing simple to use json mappings.
Installation
-
Add the dependency to your
shard.yml
:dependencies: jsonable: github: evvo/jsonable
-
Run
shards install
Usage
class User
include Jsonable
getter test_field = ["string1", "string2"]
public_json_fields [["test_field"]]
end
user = User.new
user.get_json # { "test_field" : ["string1", "string2"] }
The public_json_fields
are the fields that will be included when you call the get_json
method. public_json_fields
has 2 params - for single entry and for a collection (optional):
class User
include Jsonable
getter test_field = ["string1", "string2"]
getter test_field_for_collection = ["string1", "string2"]
public_json_fields [["test_field"], ["test_field_for_collection"]]
end
user = User.new
user2 = User.new
User.get_json_collection([user, user2]) # [{ "test_field_for_collection" : ["string1", "string2"] } ...]
Testing
You can run the tests by executing:
foo@bar:~$ crystal spec
Development
TODO: Write development instructions here
Contributing
- Fork it (https://github.com/evvo/jsonable/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
- Evtimiy Mihaylov - creator and maintainer
Repository
jsonable
Owner
Statistic
- 2
- 0
- 0
- 1
- 0
- over 5 years ago
- May 1, 2019
License
MIT License
Links
Synced at
Sun, 17 Nov 2024 07:46:14 GMT
Languages