Sample code for 30+ languages & platforms
Perl

Extract PDF from JSON

See more JSON Examples

Demonstrates how to extract a PDF file contained within JSON. The file is represented as a base64 string within the JSON. Note: This example can extract any type of file, not just a PDF file.

Chilkat Perl Downloads

Perl
use strict;
use warnings;
use Chilkat2;

my $json = Chilkat2::JsonObject->new;

# Load the JSON.
my $success = $json->LoadFile('qa_data/json/JSR5U.json');
if (!$success) {
    print $json->LastErrorText, "\n";
    exit;
}

# The JSON we loaded contains this:

#     {
#     ...
#     ...
#       "data": {
#         "content": "JVBERi0xLjQ..."
#       }
#     ...
#     ...
#     }

my $sb = Chilkat2::StringBuilder->new;
$json->StringOfSb('data.content', $sb);

my $bd = Chilkat2::BinData->new;
$bd->AppendEncodedSb($sb, 'base64');

$success = $bd->WriteFile('qa_output/a0015.pdf');