Hi,
I am decoding a largish file of JSON, and would like to give nice error messages. If I use a Json.Decode.Decoder
there is no context describing the position within the JSON that could be used to help with this.
For example, I might like an error message like:
The field 'date' must be in ISO format (like 2020-01-30):
204| someRecord : {
205| date : 1234,
^^^^^^^^^^^
206| ...
I think to do this, I would need to write a Parser
for JSON from scratch. Never actually looked at the code, but I suspect that the String -> JSON part happens in javascript, and Elm works with the in-memory JSON after that.
If I can’t do that, perhaps an easier way might be to track the positional context through the structure of the JSON, to give an error message like this:
The field 'date' must be in ISO format (like 2020-01-30):
At 'someArray[5].someRecord.date', the value given is 1234, which is not in ISO format.
Any ideas how to accomplish this? Is there some transformation that can be built on top of a Decoder to always give this context, or perhaps even a package that already does this?