We have a large code base that makes copious use of the JSON v1 API:
use JSON;
my $json = objToJson($data);
my $data = jsonToObj($json);
We would like to upgrade to JSON v2, so we can start using it in new code, and because we've been encountering other modules that depend on the v2 API.
However, if I have stored a utf8-string created by objToJson()
, it will no longer be decoded in the same way by JSON::XS (which is what JSON v2 uses behind the scenes).
use JSON;
use JSON::XS;
use warnings;
use strict;
my $data = ["\x{263a}b"];
my $encoded = JSON::objToJson($data);
print "different!\n"
unless JSON::jsonToObj($encoded)->[0] eq JSON::XS::decode_json($encoded)->[0];
print "different!\n"
unless JSON::jsonToObj($encoded)->[0] eq JSON::XS->new->decode($encoded)->[0];
Is there any way for us to upgrade to JSON v2, but still leave around the v1 API for backward compatibility with existing code?
Modules should use a new name when they do drastic changes like that. In this case, the fact that JSON 2.x is mostly a wrapper for JSON::XS conveniently means that's kind what they did.
I recommend:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With