JSON::Relaxed::ErrorCodes -- Error messages
If the document cannot be parsed, JSON::Relaxed will normally throw an exception.
In legacy mode, JSON::Relaxed returns an undefined value instead and sets the following error indicators:
$JSON::Relaxed::err_id
A unique code for a specific error.
$JSON::Relaxed::err_msg
An English description of the error, including an indication where the error occurs.
When using object-oriented mode, these can be easily retrieved using the parser methods err_id() and err_msg().
Following is a list of all error codes in JSON::Relaxed:
missing-input
No input was found. This can be caused by:
$parser->decode() $parser->decode(undef)
empty-input
The string to be parsed has no content beside whitespace and comments.
$parser->decode('') $parser->decode(' ') $parser->decode('/* whatever */')
unclosed-inline-comment
A comment was started with /* but was never closed. For example:
$parser->decode('/*')
invalid-structure-opening-character
The document opens with an invalid structural character like a comma or colon. The following examples would trigger this error.
$parser->decode(':') $parser->decode(',') $parser->decode('}') $parser->decode(']')
multiple-structures
The document has multiple structures. JSON and RJSON only allow a document to consist of a single hash, a single array, or a single string. The following examples would trigger this error.
$parse->decode('{}[]') $parse->decode('{} "whatever"') $parse->decode('"abc" "def"')
unknown-token-after-key
A hash key may only be followed by the closing hash brace or a colon. Anything else triggers
unknown-token-after-key
. So, the following examples would trigger this error.$parse->decode("{a [ }") } $parse->decode("{a b") }
unknown-token-for-hash-key
The parser encountered something besides a string where a hash key should be. The following are examples of code that would trigger this error.
$parse->decode('{{}}') $parse->decode('{[]}') $parse->decode('{]}') $parse->decode('{:}')
unclosed-hash-brace
A hash has an opening brace but no closing brace. For example:
$parse->decode('{x:1')
unclosed-array-brace
An array has an opening brace but not a closing brace. For example:
$parse->decode('["x", "y"')
unexpected-token-after-colon
In a hash, a colon must be followed by a value. Anything else triggers this error. For example:
$parse->decode('{"a":,}') $parse->decode('{"a":}')
missing-comma-between-array-elements
In an array, a comma must be followed by a value, another comma, or the closing array brace. Anything else triggers this error. For example:
$parse->decode('[ "x" "y" ]') $parse->decode('[ "x" : ]')
unknown-array-token
This error exists just in case there's an invalid token in an array that somehow wasn't caught by
missing-comma-between-array-elements
. This error shouldn't ever be triggered. If it is please let me know.unclosed-quote
This error is triggered when a quote isn't closed. For example:
$parse->decode("'whatever") $parse->decode('"whatever') }