Skip to content
New issue

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

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

Already on GitHub? # to your account

Is it possible to add line number into the Report? #59

Closed
feiniao0308 opened this issue Jun 27, 2013 · 16 comments
Closed

Is it possible to add line number into the Report? #59

feiniao0308 opened this issue Jun 27, 2013 · 16 comments
Labels

Comments

@feiniao0308
Copy link

It's different to locate the error in current Report format as follows for large JSON file. Is it possible to add line number into Report to denote which line is the pointer(schema or instance)?

com.github.fge.jsonschema.report.ListProcessingReport: failure---
BEGIN MESSAGES
---error: instance type does not match any allowed primitive type
level: "error"
schema: {"loadingURI":"#","pointer":"/properties/version"}
instance: {"pointer":"/version"}
domain: "validation"
keyword: "type"
expected: ["integer"]
found: "number"
--- END MESSAGES ---

Thanks,
Hai

@fge
Copy link
Collaborator

fge commented Jun 27, 2013

Well, that is not impossible, but it will be immensely difficult.

For this, I'd need to parse by hand and retain all location information... And manage to maintain that information during parsing, and put it in reports. Which means I need to put it in the schema.

This is all the more difficult that once the JSON is parsed into a JsonNode, location information is lost. I'd need to study that a little more, maybe Jackson already has a parser implementation from which you can retrieve location information...

@feiniao0308
Copy link
Author

Thanks for your quick response, hope this feature will be implemented later.

@feiniao0308
Copy link
Author

Hello,

Any update on this issue. I just found there's a Class in Jackson to trace the line location, please see the Class in http://jackson.codehaus.org/1.3.4/javadoc/org/codehaus/jackson/JsonLocation.html . Can we use this Class to add error line location into the report? Could you please tell me how to implement it?

Thanks,
Hai

@pmseltmann
Copy link

I've done something like this before.
I index the line number of each json property before itis parsed into a native data type with its key path. Then when reporting the schema error, I lookup the original line number using the key path returned in the error and add it to the error object.

@feiniao0308
Copy link
Author

Thanks for sharing the idea.

Could you please send me the code implementation? Please send it to hai_lh@126.com. Thanks a lot!!!

@fge
Copy link
Collaborator

fge commented Feb 8, 2014

Hello,

A gist showing how you do it would interest me as well.

@feiniao0308
Copy link
Author

I'm also waiting for response from pmseltmann.

@pmseltmann
Copy link

My solution was in javascript but maybe it can still be helpful. I forked the popular jsonlint JSON parser to index the line numbers of the source string. The parser returns an object with the parsed json object and a lineIndex object containing an index with all the json key-paths and their corresponding line numbers.
https://github.com/pmseltmann/jsonlint

I used the tv4 json-schema validator (https://github.com/geraintluff/tv4) and used the resulting 'schema-key' from each error to lookup the original line number in my I then lookup the 'schema-key' from lineIndex object and get the line number. (I transform 'schema-key' to match the keyPath. Mostly converting '/' to '.'.

@fge
Copy link
Collaborator

fge commented Feb 21, 2014

With Jackson, it is a little more complicated ;) When using a parser, you do have JsonLocation though, which contains line/column information; the harder part remains: integrating that into the code.

In any event, this will be part of -core, not -validator.

@fge
Copy link
Collaborator

fge commented Apr 8, 2014

OK, this will be in for 3.0. I already have a JsonParser which can collect line number information. But it cannot be integrated in 2.1.x/2.2 (too complicated and would require API changes which come too late at this point).

@fge fge closed this as completed Apr 8, 2014
@sellis
Copy link

sellis commented May 12, 2014

Where is the JsonParser which can collect line number information? Is it part of another project? Do you mean you are changing Jackson itself? Any estimate on when 3.0 will be available? Sorry for all the questions. Thanks.

@fge
Copy link
Collaborator

fge commented May 12, 2014

@sellis the work is here; however, at this moment I am working on another of my projects; I will resume work on JSON Schema validator next month for a first beta release probably in mid July.

@sellis
Copy link

sellis commented May 12, 2014

Thanks a lot for your response!

@bharatsavanur11
Copy link

I have completed a project in java for json validation with line number using jackson. Basically as @fge has coorectly said, we have to maually parse the data and create JSONNode objects at runtime.

Please let me know incase of any help is needed.

@hung-fq
Copy link

hung-fq commented Mar 13, 2017

@bharatsavanur11
Could you please send me your implementation? It will help me so much to solve problem in my project.
I really appreciate your help.
My email: hungfq@gmail.com

@ostwalankit
Copy link

@bharatsavanur11 , Can you please share your implementation over here or on email ostwalankit@gmail.com . It will help me solve my issue. I really appreciate your help. Thanks.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants