Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request to expose error location-line and column #68

Closed
erezfz opened this issue May 14, 2015 · 8 comments
Closed

Request to expose error location-line and column #68

erezfz opened this issue May 14, 2015 · 8 comments

Comments

@erezfz
Copy link

erezfz commented May 14, 2015

Hi,
I would like to have additional information on every error, describing WHERE is the text in the tested JSON file/string which failed validation.
The location info should include:
line number (most important),
column number (column is were the failed text token started),
number of characters of error text token (this parameter is nice-to-have)

@mafintosh
Copy link
Owner

Send me a PR for this and I'll merge it :)

@erezfz
Copy link
Author

erezfz commented May 14, 2015

Hi, PR as in pull request?

@mafintosh
Copy link
Owner

yea

@mattanbi
Copy link

mafintosh, Can you suggest what's the best way to implement this?

@chrahunt
Copy link
Collaborator

Is there a purpose for this feature other than to make it easier to troubleshoot invalid JSON? When you enable verbose mode, errors include the location of specific parts of the JSON that fail validation. With this information, it should be pretty straightforward to locate the source of an issue in the JSON being validated. @Kaizer200 if you get a chance, take a look at this option and see if it meets your needs.

@mattanbi
Copy link

I would like to mark the errors on specific lines in the editor embedded in my web-application.

@chrahunt
Copy link
Collaborator

One way to accomplish that would be to create a wrapper around is-my-json-valid that would try to validate the JSON in verbose mode as mentioned above. If there is an error, check for a valid field property in the error object, split it on the .s, and then use that to identify which property to select/highlight.

You will need some way to associate the parsed JSON object with the location of the individual tokens in the JSON itself. One way to do that would be to generate a JSON parser that would return an object that has information about the location of each of the tokens, or extract this information about the specific error-causing portion of your JSON. Things like your target speed and the input size you want to be able to handle will dictate which is more appropriate. If you want to do it client-side, jison could be used to generate the parser. The same author created jsonlint, which could be used as a basis for your parser, and you can find information on getting token locations here.

After considering it for the above, and since it already provides the error location in verbose mode, I think this capability may be outside the scope of this module. What are your thoughts @mafintosh?

@chrahunt
Copy link
Collaborator

Closing this based on the previous comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants