You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
it's not an issue but since I found no place to post my question I put it here.
So my question is, is it possible to get the line where the exception was throw in the file ?
For exemple in this file: { "none" { "name": "holaaaaa" } }
I would like the exception to return 2 for exemple.
Thanks.
Parse errors will be thrown as json::parse_error exception which have a public member byte indicating the byte count to indicate the error location. Error messages look like this:
[json.exception.parse_error.101] parse error at 7: unexpected end of input; expected ':'
I am new to this library, but so far it works great. Thanks for your good work! Just one question: I really need this feature, we need to know where in the input file the error was. How can I use this new feature, or when will it be released to the main branch?
@haimat This feature is planned for the 3.0.0 release - as introducing new exceptions means a change in the public API, we cannot release it to the 2.x.x track. In the meantime, you can check out the feature branch for this feature. It implements the described feature, but may change in the future when we merge it into the develop branch. I would look forward to hearing of your experiences.
@nlohmann Thank you very much for the quick response. I have tested this new feature and it definitely is an improvement! However, having only the byte number in the stream without knowing the context where (i.e. in which line) the error is within the file is a bit hard to read. Any chance you will implement a translation from byte number to line/column?
@haimat I'm not sure how much effort this is, because the lexer skips all whitespace. To track a line/column count, this code needs to be adapted. I shall have a look at this, but other issues have priority.
@nlohmann Does that mean the indicated byte-position is calculated after stripping away the whitespaces? In that case I am afraid it does not help at all, because then I could never match it against the original file :(
This issue is nearly complete. If anyone would like to have a look at the soon-to-be-merged state, please have a look at branch https://github.com/nlohmann/json/tree/feature/exceptions_3.0.0. It contains parse_error exceptions with a byte count to the error, and only the documentation needs some final touches.
Activity
nlohmann commentedon Aug 29, 2016
With issue #244, the exceptions will be overworked and parse errors will be annotated with a byte count to indicate the error location.
working on user-defined exceptions (#244), added location to parse er…
nlohmann commentedon Nov 14, 2016
Parse errors will be thrown as
json::parse_errorexception which have a public memberbyteindicating the byte count to indicate the error location. Error messages look like this:haimat commentedon Dec 11, 2016
I am new to this library, but so far it works great. Thanks for your good work! Just one question: I really need this feature, we need to know where in the input file the error was. How can I use this new feature, or when will it be released to the main branch?
nlohmann commentedon Dec 11, 2016
@haimat This feature is planned for the 3.0.0 release - as introducing new exceptions means a change in the public API, we cannot release it to the 2.x.x track. In the meantime, you can check out the feature branch for this feature. It implements the described feature, but may change in the future when we merge it into the develop branch. I would look forward to hearing of your experiences.
haimat commentedon Dec 11, 2016
@nlohmann Thank you very much for the quick response. I have tested this new feature and it definitely is an improvement! However, having only the byte number in the stream without knowing the context where (i.e. in which line) the error is within the file is a bit hard to read. Any chance you will implement a translation from byte number to line/column?
nlohmann commentedon Dec 12, 2016
@haimat I'm not sure how much effort this is, because the lexer skips all whitespace. To track a line/column count, this code needs to be adapted. I shall have a look at this, but other issues have priority.
haimat commentedon Dec 12, 2016
@nlohmann Does that mean the indicated byte-position is calculated after stripping away the whitespaces? In that case I am afraid it does not help at all, because then I could never match it against the original file :(
nlohmann commentedon Dec 12, 2016
@haimat No, it is the exact byte count, including whitespace.
🔨 started with user-defined exceptions #301 #244
nlohmann commentedon Mar 8, 2017
This issue is nearly complete. If anyone would like to have a look at the soon-to-be-merged state, please have a look at branch https://github.com/nlohmann/json/tree/feature/exceptions_3.0.0. It contains parse_error exceptions with a byte count to the error, and only the documentation needs some final touches.
nlohmann commentedon Mar 12, 2017
Merged this feature into
develop. All there is left to do is to document the changes between old and new exceptions in the wiki page.