Wrong JSON string, no array, no object, no number, no string, no atom

I have a problem handling json with perl and I don't know if the problem comes from json or my script. Here is json:

test.json

{ "count":3, "entries": [ { "id":85, "application":AuditExampleLogin1, "user":admin, "time":"2011-11-22T10:29:37.422Z", "values": null }, { "id":87, "application":AuditExampleLogin1, "user":admin, "time":"2011-11-22T10:30:56.235Z", "values": null }, { "id":89, "application":AuditExampleLogin1, "user":admin, "time":"2011-11-22T10:33:15.000Z", "values": null } ] } 

Here's the script:
script.pl

 #!/usr/bin/perl -w use strict; use JSON; open FILE, 'test.json' or die "Could not open file inputfile: $!"; sysread(FILE, my $result, -s FILE); close FILE or die "Could not close file: $!"; my @json = @{decode_json($result)}; 

And finally, the error I get:
Error

 malformed JSON string, neither array, object, number, string or atom, at character offset 86 (before "AuditExampleLogin1,\n...") at ./script.pl line 7. 

Q: Can someone tell me if the problem comes from json or my script and what to change anyway?

FYI json comes from an audit of Alfresco api .

+6
source share
2 answers

It works if the values ​​are Audit ... and admin. Line

 my @json = @{decode_json($result)}; 

should just be

 my @json = decode_json($result); 
+2
source

It:

 "application":AuditExampleLogin1, 

... invalid JSON. AuditExampleLogin1 not an array, object, number, string or atom. I don’t know what it is, so I can’t tell you what to change it.

If it's a string, you need to wrap it in " .

See also: JSON Lint .

+10
source

Source: https://habr.com/ru/post/902120/


All Articles