| None. |
|
Returns a readable message describing the last recoverable JSON failure. When ParseJson or LoadJson returns 0, this is where the story is: a bounded, human-readable English description of what was wrong with the data - perfect for a log line or an "this save file is corrupt" dialog. JsonStringify and SaveJsonAtomic also set it when serialization itself fails (for example output over the 64 MiB limit). JsonError heads a family of five diagnostics that pin the failure down together: JsonErrorLine / JsonErrorColumn: one-based position in the source JsonErrorOffset: zero-based UTF-8 byte offset JsonErrorPath: $-rooted logical path to the bad value A successful parse or load clears the whole family, so the values always describe the most recent failure - read them straight after the call that failed, before parsing anything else. Note that a LoadJson that failed to even read the file reports through FilesystemError instead, and clears the JSON diagnostic. The diagnostics are context-local: the main program and each Job worker see only their own failures. For the full rules, see the Application Data language reference. See also: JsonErrorLine, JsonErrorColumn, JsonErrorOffset, JsonErrorPath, ParseJson, FilesystemError. |
; JsonError Example
; -----------------
q$=Chr(34) ; Double-quote character, for building JSON text
; A save-game file that was corrupted: 12x5 is not a number
line1$="{"
line2$=q+"player"+q+": "+q+"Aria"+q+","
line3$=q+"gold"+q+": 12x5"
line4$="}"
src$=line1+Chr(10)+line2+Chr(10)+line3+Chr(10)+line4
Print "Parsing this broken save-game:"
Print src
Print ""
; The parse fails, returning zero and setting the diagnostics
save=ParseJson(src)
Print "ParseJson returned "+save+" (0 = failed)"
Print ""
; JsonError returns a human-readable description of what went wrong
Print "JsonError: "+JsonError()
Print "(at line "+JsonErrorLine()+", column "+JsonErrorColumn()+")"
Print ""
Print "Press any key to close the example"
WaitKey
End