Skip to content

JSON parsing with accumulative errorsΒ #578

Open
@eckyputrady

Description

@eckyputrady

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions