#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; { my @JSON_MODULES = qw( JSON::XS JSON JSON::PP JSON::Tiny ); my $json_class; for my $module (@JSON_MODULES) { if (eval "require $module;") { $json_class = $module; last; } } die "No JSON parsing class found. $0 requires one of ", join(', ', @JSON_MODULES), ".\n" unless $json_class; warn "Using JSON module '$json_class'.\n"; $json_class->import(qw(encode_json decode_json)); } my $json = '{"foo":"bar", "biff":["baz","buzz"]}'; print "\nData structure parsed from JSON:\n", Dumper(decode_json($json));