-4

I have two data structures in JSON format. They are deeply nested hashes. How can I deeply compare these structures?

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
user2260554
  • 1
  • 1
  • 2

1 Answers1

3

You can decode the JSON using JSON which just uses JSON::XS if it is installed on your system.

use JSON;
use Data::Compare;

my $h1 = JSON->new->utf8->decode($perl_scalar1);
my $h2 = JSON->new->utf8->decode($perl_scalar2);
my $c = Data::Compare->new($h1, $h2);
print 'structures of $h1 and $h are ',
$c->Cmp ? "" : "not ", "identical.\n";
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339