haskell / haskell/aeson

Expose Data.Aeson.Encoding.Builder

Open
#644 3 comments 2 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

At work we have a JSON schema which demands composite keys for objects of this form:

```
"_": ...
```

Now, we used the venerable `toKey (n, d) = Text.pack (show n ++ '_' ++ show d)` but this turned out out to show up in our profiling and really was taking 10% of our overall runtime! So we went for some cruel hack:

```haskell
toKey (n ,d) = Encoding.unsafeToEncoding $
Builder.char7 '"' <> Builder.intDec r <> Builder.char7 '_'
<> Encoding.fromEncoding (Encoding.day d) <> Builder.char7 '"'
```

Unfortunately this results in invalid JSON as `Encoding.day` is wrapped into quotes! It would be really neat if we could access the unsafe stuff from Data.Aeson.Encoding.Builder to use the `Day` encoding without quotes.

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.