[feature request] Function printing the error location in source json would be beneficial
Here is an example what it might print:
{["a","b","c",]}
(expecting array element) --------------------^
This would be very convenient for quick identification of problems in jsons.
True, but this would require caching the original JSON data in the error struct, which is not practical at least for json_load_callback() and json_loadf() if the input file is not seekable.
It would also be very hard to get the caret to point to the correct spot when complex unicode characters are included in the input JSON.
Re: [jansson] [feature request] Function printing
the erro Perhaps this could be done as a Jansson helper function, which the caller hands the source JSON that caused the error, the previously reported error struct, and a file descriptor for the output. There might also have to be arguments constraining the output (e.g. how much context is to be shown), since JSON strings can be very long.
Or, this could be handled by the caller, leaving Jansson out of the loop.
Dan
At 4:11 AM -0800 1/8/14, Petri Lehtinen wrote: True, but this would require caching the original JSON data in the error struct, which is not practical at least for json_load_callback() and json_loadf() if the input file is not seekable. It would also be very hard to get the caret to point to the correct spot when complex unicode characters are
included in the input JSON.
Reply to this email directly or view it on GitHub.
Daniel T. Griscom [email protected] Suitable Systems http://www.suitable.com/ 1 Centre Street, Suite 204 (781) 665-0053 Wakefield, MA 01880-2400
A helper function sounds good to me. It could also optionally return the data as a heap-allocated string.
The unicode formatting problem remains, though.
I added a proof of concept. The errors are not as specific as described in this ticket, but that's inherent from how Jansson parses I guess. Anyway, it simply uses the contents of json_error_t
Oh and btw, does error.position refer to the bytes or character points for UTF-8?
error.position is just plain bytes.