haskell / aeson

A fast Haskell JSON library
Other
1.25k stars 322 forks source link

Parse exception raised for combination of .: and .!= #1110

Open quintenkasteel opened 2 months ago

quintenkasteel commented 2 months ago

We use aeson-1.4.7.1.

The following code raises an exception:

for the type: data = Field {field :: Text} field .: "fieldName" .!= "" raises an exception.

It would be great if this could raise an compile error instead.

phadej commented 2 months ago

I don't understand. What you mean by raises an exception?

Please provide a complete reproducer.

quintenkasteel commented 2 months ago

If i have a JSON record that looks like the following: { "fieldName": null }

If i use the parser: field .: "fieldName" .!= "" it will compile. But it will always raise an JSONConversionException: "key \"fieldName\" not found"

I would like to get an compile error, as this code is not valid. The parser should use the parser for Maybe values: field .:? "fieldName" .!= ""

I can code a minimal example if you need more clarification.