Bloehdian has asked for the wisdom of the Perl Monks concerning the following question:
Hey monks,
I have trouble to get the following code to run:
use JSON::Path; $json = q( { "array": [ 1, 2, 3], "string": "string_value", "object": +{ "obj1": "val1", "obj2": "val2" } } ); $arr_path = JSON::Path->new( q($.array) ); $scal_path = JSON::Path->new( q($.string) ); $value = $arr_path->value(); if ( ! ( defined ref $value ) ) { print "SCALAR\n" } elsif ( ref $value eq q(ARRAY) ) { print "ARRAY\n" } else { print "NEITHER" }
I get the following error message:
Use of uninitialized value $json_object in concatenation (.) or string + at /usr/local/share/perl/5.20.2/JSON/Path/Evaluator.pm line 84. Unable to decode as JSON: malformed JSON string, neither tag, array, +object, number, string or atom, at character offset 0 (before "(end o +f string)") at /usr/local/share/perl/5.20.2/JSON/Path/Evaluator.pm li +ne 81. at /usr/local/share/perl/5.20.2/JSON/Path/Evaluator.pm line 79.
According to JSONLint $json is valid JSON. Therefore I do not understand the error message.
What's goin' wrong?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Ambiguous error message from JSON::Path
by choroba (Cardinal) on Apr 16, 2018 at 07:31 UTC | |
|
Re: Ambiguous error message from JSON::Path
by Discipulus (Canon) on Apr 16, 2018 at 07:36 UTC |