0

I get the error

EXECUTION FAILED ...malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)")"

when I parse my JSON string from DB to this snippet.

my $json_geno1 = decode_json($geno_set_one);
warn Dumper($json_geno1); 

Am I missing something ? The json string is from the Database.

 $VAR1 = [
   '{"":"No Call","rs1032807":"AG","rs718757":"AG","rs6557634":"CC","rs995553":"CG","rs6166":"AG","rs4925":"AA","rs502843":"GT","rs725029":"No Call","rs3904872":"GG","rs1402695":"TT","rs719601":"AA","rs2374061":"AG","rs952503":"TT","rs1801262":"AG","rs5215":"CT","rs978422":"CC","rs12828016":"GG","rs958388":"AG","rs999072":"CT","rs967344":"AG","rs2207782":"CC","rs349235":"AA","rs1074553":"CT","rs1395936":"AG","GS35220":"CT","rs7627615":"AG","rs727336":"AG","rs2077774":"AC","rs8065080":"CC","rs1131498":"TT","rs2247870":"No Call","rs803172":"TT","rs1541290":"AG","rs1414904":"AA","rs1928045":"No Call","rs2077743":"GT","rs2361128":"No Call","rs3795677":"AG","rs1030687":"CT","rs156318":"GG","rs952768":"CC","rs1363333":"TT","rs7298565":"AG","rs310929":"CC","rs2369898":"CT","rs1327118":"CC","rs4619":"AG","rs965323":"TT","rs2887851":"AG","rs1862456":"GT","rs6759892":"GT","rs753381":"AG","rs1805034":"CC","rs1812642":"AA","rs4075254":"CT","rs1805087":"AA","rs532841":"CT","rs951629":"GG","rs2286963":"GG","rs763553":"CT","rs1074042":"GG","rs2241714":"GG","rs894240":"TT","rs522073":"CT","GS35205":"TC","rs1368136":"TT","rs1426003":"GG","rs2016588":"No Call","rs621277":"No Call","rs727081":"GG","rs1392265":"AC","rs1079820":"No Call","rs4843075":"AG","rs156697":"CC","rs11096957":"AC","rs1952161":"GG","rs1961416":"AG","rs1585676":"GG","rs890910":"TT","rs171953":"AG","rs1843026":"CC","rs1515002":"CC","rs756497":"No Call","rs1293153":"No Call","rs754257":"GT","rs649058":"AG","rs726957":"AG","rs728189":"No Call","GS34251":"TC","rs3742207":"No Call","rs210310":"CT","rs2216629":"AG","rs1541836":"CT","rs722952":"CT","rs1105176":"GG"}'
    ];

Thanks

1
  • 4
    Please show your JSON data Commented Oct 10, 2014 at 10:36

4 Answers 4

5

You should probably use:

my $json_geno1 = decode_json($VAR1[0]);

because $VAR1 is now an array.

This JSON is valid (I've tested it in PHP) and I get object from this string without a problem.

Sign up to request clarification or add additional context in comments.

Comments

0

I got exactly same error. Which got resolved by removing for below code

my $json;
{
  local $/;
  open ($fh, "+<temp.json") or die $!;
  my $json = <$fh>;
  close $fh;
}

and got resolved by removing the my from line number 5.

my $json;
{
  local $/;
  open ($fh, "+<temp.json") or die $!;
  $json = <$fh>;
  close $fh;
}

Comments

0

I got this* msg too, when i tried to call the read function like this:

perl json_read_test.pl /server/lib/Schema/user_data.schema.json

When I used it with ./ or without / or with full path name, that solved the problem.

** "malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "(end of string)") at /usr/share/perl5/JSON.pm line 190."

Comments

-2
my $json_geno1 = decode_json($geno_set_one->[0]);
warn Dumper($json_geno1);

1 Comment

Hey alexandr! Welcome to SO! Mind adding a bit more "meat" to your answer? we usually don't do code-only answers, as they are not super helpful for future visitors :) a bit of context would be appeciated ^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.