0

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?

gregsdennis
  • 7,218
  • 3
  • 38
  • 71
Sprotty
  • 5,676
  • 3
  • 33
  • 52
  • ` I need to get line numbers for the objects it passes back to me` that's not usual.. can you elaborate more on what you are trying to achieve/ – Chetan Jan 03 '22 at 08:59
  • 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. – Sprotty Jan 03 '22 at 09:09
  • The output for JsonSchema.Net includes pointers to where the bad data is (see `instanceLocation`). This will give you the structural details. Is this insufficient? – gregsdennis Apr 07 '22 at 02:08

0 Answers0