Skip to content

Commit

Permalink
Add example of using mapping to parse array (#5993)
Browse files Browse the repository at this point in the history
Currently json documentation is missing a very common example of parsing array of objects using mapping. 

This PR add this example into documentation (in section about using `from_json`).
  • Loading branch information
esse authored and Serdar Dogruyol committed Apr 23, 2018
1 parent 6564d6c commit 1c4e4e8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/json/mapping.cr
Expand Up @@ -24,6 +24,10 @@ module JSON
# house.address # => "Crystal Road 1234"
# house.location # => #<Location:0x10cd93d80 @lat=12.3, @lng=34.5>
# house.to_json # => %({"address":"Crystal Road 1234","location":{"lat":12.3,"lng":34.5}})
#
# houses = Array(House).from_json(%([{"address": "Crystal Road 1234", "location": {"lat": 12.3, "lng": 34.5}}]))
# houses.size # => 1
# houses.to_json # => [{"address":"Crystal Road 1234","location":{"lat":12.3,"lng":34.5}}]
# ```
#
# ### Usage
Expand Down

0 comments on commit 1c4e4e8

Please sign in to comment.