haskell / haskell/aeson

Consider adding a ToObject class

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

Description

I semi-regularly find myself using APIs that support attaching some form of user-provided metadata, but the metadata must be an object. As an example, the Segment HTTP API has a number of properties that just take grab-bags of user metadata, so my API is looking about like this:

``` haskell
track :: ToJSON a => SegmentClient -> Context -> EventName a -> a -> IO ()
track c ctxt n val = ... v
where
(Object v) = toJSON val
```

I'm not terribly crazy about having to do partial matching just to extract a value, and think it would be lovely if there was a class that be an instance only for data types that made sense to be generated as objects that could use the same TH or Generic instance generation:

```
class ToObject a where
toObject :: a -> Object
```

Contributor guide

Open the contributing guide

Research direction

Review the existing ToJSON class and the TH or Generic instance-generation mechanisms mentioned in the issue, then read the discussion for design constraints. Done means the proposed object-only abstraction has an agreed design, supports the relevant instance-generation paths, and avoids partial matching for object metadata.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.