-
-
Notifications
You must be signed in to change notification settings - Fork 593
Add validate function that reports JSON file line number in error? #156
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
Comments
You're talking about line numbers for validation errors, not for invalid JSON presumably? If so I think I feel the same as I did there -- there's a piece of that that seems like it's the responsibility of I don't want to get in the business of writing a JSON parser, but I'd bet there probably is one that could do that. I can give this some more thought probably, but that's the direction I'd think is worth pursuing. |
Is it possible to do this with the json parser in the Python standard library? |
The JSON decoder from the standard python library does not provide a source location information. I am not aware of one that does. |
Full disclosure: I'm the maintainer of the package below. There is now a new Python package that solves this use case: https://github.com/open-alchemy/json-source-map Installation: For example, the following JSON document: {
"foo": "bar"
} Produces the following source map:
|
@sspTest - I don't remember. I think we ended up using YAML instead of JSON and PyDantic. But I don't know if there we had good error messages mentioning the line number in the end or which YAML package we used. |
Would it be possible to add a validate function that takes a JSON file name (or file handle or text ... something where line number info is available) and reports the line number if there is an error?
Maybe there's a trick to embed line number info in the dict generated by the JSON parser? Maybe build a second dict with identical structure, but line numbers as values instead of the actual content?
For my use case I don't care about performance (speed, memory), but it would be very helpful to get a line number in the error.
I'm new to JSON schema, so apologies if this is a stupid and impossible feature request.
The same question was asked before by @BrunoQC here: #90 (comment).
The text was updated successfully, but these errors were encountered: