Skip to content

Instantly share code, notes, and snippets.

@tobyink
Created November 12, 2014 11:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobyink/53b1ce74829a278b529e to your computer and use it in GitHub Desktop.
Save tobyink/53b1ce74829a278b529e to your computer and use it in GitHub Desktop.
use v5.14;
use JSON::PP;
use JSON::Hyper;
use Data::Dumper;
use Devel::Confess;
# Construct a URI which has some JSON data. I'm using a
# data: URI because I'm too lazy to upload some JSON
# somewhere, but any URI that returns JSON should be OK.
#
my $uri = do {
require URI::data;
my $tmp = URI::->new('data:');
$tmp->media_type('application/json');
$tmp->data('{ "answer": 42 }');
$tmp;
};
my $stuff = JSON::PP::->new->decode(<<"JSON");
{
"foo": { "\$ref": "$uri" },
"bar": []
}
JSON
print Dumper($stuff);
JSON::Hyper::->new->process_includes($stuff, 'http://example.com/', !!1);
print Dumper($stuff);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment