Last active
December 19, 2015 00:29
-
-
Save tadzik/5868712 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# code | |
use JSON::Unmarshal; | |
class Dog { | |
has Str $.name; | |
has Str $.race; | |
has Int $.age; | |
} | |
class Person { | |
has Str $.name; | |
has Int $.age; | |
has Dog $.dog; | |
} | |
my $json = q/ | |
{ | |
"name" : "John Brown", | |
"age" : 17, | |
"dog" : { | |
"name" : "Roger", | |
"race" : "corgi", | |
"age" : 4 | |
} | |
} | |
/; | |
my $p = unmarshal($json, Person); | |
say $p.perl; | |
# output (prettified) | |
Person.new(name => "John Brown", | |
age => 17, | |
dog => Dog.new(name => "Roger", race => "corgi", age => 4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment