0

What is the difference between json and json::PP in Perl?

I meet this error when use Json and Json:PP when writing perl script in opensips

ERROR:core:XS_OpenSIPS__Message_log: 
perl warning: Prototype mismatch: sub main::decode_json ($) vs none.

I have problem with these codes:

my %postObject = ("callId" => $callID);
$postObject{'endTime'} = time() . "";
$postObject{'key'} = "12345@qwerty";
my $post_data = encode_json \%postObject;
nvnhcmus
  • 1
  • 3
  • 1
    Please show the corresponding [`use`](https://perldoc.perl.org/functions/use.html) statement for your JSON module. Your code works fine with both [`JSON`](https://metacpan.org/pod/JSON) and [`JSON::PP`](https://metacpan.org/pod/JSON::PP) on my machine (Ubuntu 17.10, Perl version 5.26.1). What version of Perl are you using? – Håkon Hægland Apr 02 '18 at 10:57
  • i am using perl (v5.20.2) in Debian 7.11 (64 bit) with use ```use JSON::PP; ``` in my script. – nvnhcmus Apr 03 '18 at 07:00

1 Answers1

2

The "Prototype mismatch" warning typically means that you've defined a sub twice in some way, and the two definitions' prototypes don't match.

Do you have a sub decode_json ($) in your main code somewhere? If you do, I'd suggest removing or renaming it, because it is conflicting with decode_json from one of the JSON modules. If you don't, then you may be getting a second decode_json from another module you are loading, in which case you'd have to track that down, or provide us with a Minimal, Complete, and Verifiable example.

I'd strongly recommend turning on warnings, because then you will additionally get "Subroutine redefined" warnings to help you track the issue down.

haukex
  • 2,973
  • 9
  • 21