Skip to content

System.Text.Json Retrieve Line / Column Numbers #53788

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

Closed
LostTime76 opened this issue Jun 6, 2021 · 3 comments
Closed

System.Text.Json Retrieve Line / Column Numbers #53788

LostTime76 opened this issue Jun 6, 2021 · 3 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Text.Json needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Milestone

Comments

@LostTime76
Copy link

LostTime76 commented Jun 6, 2021

Apologies if the solution to this already exists, but upon initial inspection of using System.Text.Json, I cannot seem to find it. Please kindly point me in the correct direction.

I would like to be able to get line and column numbers reliably from either utf8jsonreader and [optionally / additionally] JsonDocument type APIs. Looking at Newtonsoft, it seems like the JsonTextReader supports these properties on the reader. Poking around some other issues, it seems like LineNumber was supposed to be exposed in an issue in 2019, but got left in some sort of limbo.

Using utf8jsonreader directly allows me to parse json documents in complex scenarios not supported by higher level APIs. However, this also means I would like to direct the user to the exact line and column for information or errors.

Before anybody jumps in and says that JsonException is what I am looking for (which contains line / columns), no it is not. A json document can have a perfectly valid parse-able state, but an invalid logical state based on complex logic. That complex logic is what a schema / reader can't really implement easily.

It is a shame that these properties are not exposed right now, because as I understand it, the values already exist down inside the implementation. I will have to use newtonsoft at least until these are exposed.

@LostTime76 LostTime76 added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Jun 6, 2021
@ghost ghost added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Jun 6, 2021
@ghost
Copy link

ghost commented Jun 6, 2021

Tagging subscribers to this area: @eiriktsarpalis, @layomia
See info in area-owners.md if you want to be subscribed.

Issue Details

Apologies if the solution to this already exists, but upon initial inspection of using System.Text.Json, I cannot seem to find it. Please kindly point me in the correct direction.

I am using the JsonDocument to parse JsonElements from a .json file. I have a lot of custom logic for parsing each element: properties, allowed types, etc.. that cannot be easily validated with a schema. Properties are dependent on other properties existing or not.. you can omit fields if you specify other fields or property values, yadda yadda.

I do not want to use the lower level Utf8JsonReader and re implement all of the nice things JsonDocument / JsonElement give me. It would be highly beneficial if JsonElement could implement line & column information in some form within a document, whether its just where the element starts, where it starts, ends, etc.. This allows me to directly point to a position within an input .json file to flag an error to the user so they can fix the document.

I have no reference point on how difficult this would be or the repercussions, because I am not involved in this code base.

Author: LostTime76
Assignees: -
Labels:

api-suggestion, area-System.Text.Json, untriaged

Milestone: -

@LostTime76 LostTime76 changed the title System.Text.Json JsonElement Line / Column Numbers System.Text.Json Retrieve Line / Column Numbers Jun 8, 2021
@eiriktsarpalis eiriktsarpalis added needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed untriaged New issue has not been triaged by the area owner labels Jul 16, 2021
@eiriktsarpalis eiriktsarpalis added this to the 6.0.0 milestone Jul 16, 2021
@layomia layomia modified the milestones: 6.0.0, 7.0.0 Jul 23, 2021
@layomia
Copy link
Contributor

layomia commented Jul 23, 2021

Moving to consider in .NET 7.

@eiriktsarpalis
Copy link
Member

Duplicate of #50629.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Text.Json needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Projects
None yet
Development

No branches or pull requests

3 participants