Skip to content

Instantly share code, notes, and snippets.

@tadzik
Last active December 19, 2015 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadzik/5868712 to your computer and use it in GitHub Desktop.
Save tadzik/5868712 to your computer and use it in GitHub Desktop.
# 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