2 years ago

#5068

test-img

Sprotty

Get Line/Col info from System.Text.Json.JsonElement

I have some 3rd part code that requires a System.Text.Json.JsonElement, but I need to get line numbers for the System.Text.Json.JsonElement objects it passes back to me.

Basically I'm using JsonSchema.Net to validate a JSON document, and I want to highlight the errors in the source json document. JsonSchema.Net operates on System.Text.Json.JsonElement objects.

Is it possible to get the source line number or offset from a System.Text.Json.JsonElement?

It looks like the JsonDocument holds this information in private variables, but I can't see any way to access it.

Alternatively is there any way to manually build a JsonDocument (with JsonElement children), that way I could build it myself and keep a map of positions for each JsonElement?

c#

json

system.text.json

json-everything

0 Answers

Your Answer

Accepted video resources