haskell / haskell/aeson

Documentation examples for generic instances for `ToJSONKey` fail to compile

Open
#1,145 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
1.3k
Forks
336
Avg merge
3d 7h
Merged PRs (30d)
4

Description

The documentation has an example for implementing `ToJSONKey` for a simple sum type:

```haskell
data Color = Red | Green | Blue
deriving (Show, Read, Eq, Ord)

instance ToJSONKey Color where
toJSONKey = genericToJSONKey defaultJSONKeyOptions
```

However, when trying this I get two errors:
- `No instance for ‘ToJSON Color’`
- `No instance for ‘Generic Color’`

It'd be nice to have the examples compile.

(I was surprised that `ToJSON` was needed. So I looked at the example to clarify whether I'm really supposed to have that instance or whether I'm just using the library wrong. But since the example doesn't have the `ToJSON` instance, but also doesn't compile, I'm still not 100% sure.)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.