haskell/aeson

JSON parsing with accumulative errors

Open

#578 ouverte le 24 août 2017

Voir sur GitHub
 (8 commentaires) (1 réaction) (0 assignés)Haskell (334 forks)batch import
help wanted

Métriques du dépôt

Stars
 (1 298 stars)
Métriques de merge PR
 (Merge moyen 89j 5h) (9 PRs mergées en 30 j)

Description

When parsing an incorrect JSON with Aeson, you only get the first error instead of all the errors like so:

Data.Aeson> eitherDecode "[1,19,\"a\", 20]" :: Either String [Text]
Left "Error in $[0]: expected Text, encountered Number"

It would be better to have another function to return all the errors instead of just the first one, for example:

Data.Aeson> eitherDecode "[1,19,\"a\", 20]" :: Either [(String, String)] [Text]
Left [("$[0]", "Expected Text, encountered Number"), ("$[1]", "Expected Text, encountered Number"), ("$[3]", "Expected Text, encountered Number")]

This kind of feature would be very useful in web development where errors in request payload are all checked at once to save network round trip.

I'm thinking maybe this library can be used instead of Either https://hackage.haskell.org/package/Validation-0.2.0/docs/Data-Validation.html

Guide contributeur