HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/share/doc/libjson-parse-perl/examples/json-tiny-round-trip-demo.pl
#!/usr/bin/perl
use warnings;
use strict;
use utf8;
use JSON::Tiny '0.58', qw(decode_json encode_json);
use JSON::Parse;
use JSON::Create;
binmode STDOUT, ":encoding(utf8)";
my $cream = '{"clapton":true,"hendrix":false}';
my $jp = JSON::Parse->new ();
my $jc = JSON::Create->new (sort => 1);

print "First do a round-trip of our modules:\n\n";
print $jc->create ($jp->parse ($cream)), "\n\n";

print "Now do a round-trip of JSON::Tiny:\n\n";
print encode_json (decode_json ($cream)), "\n\n";

print "🥴 First, incompatible mode:\n\n";
print 'tiny(parse): ', encode_json ($jp->parse ($cream)), "\n";
print 'create(tiny): ', $jc->create (decode_json ($cream)), "\n\n";

# Set our parser to produce these things as literals:
$jp->set_true (JSON::Tiny::true);
$jp->set_false (JSON::Tiny::false);

print "🔄 Compatibility with JSON::Parse:\n\n";
print 'tiny(parse):', encode_json ($jp->parse ($cream)), "\n\n";
$jc->bool ('JSON::Tiny::_Bool');

print "🔄 Compatibility with JSON::Create:\n\n";
print 'create(tiny):', $jc->create (decode_json ($cream)), "\n\n";

print "🔄 JSON::Parse and JSON::Create are still compatible too:\n\n";
print $jc->create ($jp->parse ($cream)), "\n";