Blitz3D+ Command Reference

JsonErrorPath$ ( )

Parameters

None.

Description

Returns a $-rooted logical path to the last JSON failure, or an empty string.

Line and column are great for small files, but in a 5000-line save you really want to know WHICH value was bad. JsonErrorPath answers in document terms: $ is the root, .name steps into an object property, [1] indexes an array element - so $.inventory[1] means "the second item in the inventory". That is the message a player or modder can actually act on.

The path is reported when the failure can identify one - typically size and type limits hit at a known value while ParseJson or LoadJson works through the document. Plain syntax errors (a missing comma, a stray bracket) often cannot name a value; then JsonErrorPath is an empty string and the positional trio JsonErrorLine / JsonErrorColumn / JsonErrorOffset is your guide instead. Robust error reporting prints the path when present and falls back to line and column.

Set together with JsonError on failure, cleared by the next successful parse or load, and context-local like the rest of the family.

For the full rules, see the Application Data language reference.

Requires Extended mode.

See also: JsonError, JsonErrorLine, JsonErrorColumn, JsonErrorOffset, LoadJson.

Example

; JsonErrorPath Example
; ---------------------
; Requires Extended mode.

q$=Chr(34)  ; Double-quote character, for building JSON text

; A save-game corrupted deep inside a nested structure:
; the second inventory item is the bare word 'nope'
src$="{"+q+"inventory"+q+":["+q+"sword"+q+",nope]}"

Print "Parsing this broken save-game:"
Print src
Print ""

save=ParseJson(src)
Print "ParseJson returned "+save+" (0 = failed): "+JsonError()
Print ""

; JsonErrorPath returns a $-rooted logical path to the failure,
; so you know WHICH value in a big document was bad
Print "JsonErrorPath: "+JsonErrorPath()
Print ""
Print "$ is the document root, .inventory the property, [1] the element."

Print ""
Print "Press any key to close the example"
WaitKey

End

Index