Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I am having some isssue with JSON decode_json functionality. I am getting error as

'"' expected, at character offset 65 (before "}") at sample.pl line 7.

Please find the below code and help me to resolve this problem

#!/usr/bin/perl use JSON qw(decode_json); use Data::Dumper; my $var = { 'POSTDATA' => '{ "emailid" : "test@test.com", "name" : "Jo +hn", "id" : "ID1020", }' }; my $postdata = $var->{POSTDATA}; my $json_decode = decode_json($postdata); print Dumper($json_decode);
Thanks

Replies are listed 'Best First'.
Re: JSON - decode_json function is not working.
by choroba (Cardinal) on Apr 13, 2013 at 00:27 UTC
    Remove the trailing comma from the JSON.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      thanks a lot.
Re: JSON - decode_json function is not working.
by RichardK (Parson) on Apr 13, 2013 at 11:45 UTC

    If your JSON is being written by a person then you could turn on relaxed which allows trailing commas and comments, but they are non standard extensions. I find this useful for config files, but use it with caution.