Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Data.Aeson.Encoding.Builder #644

Open
alexbiehl opened this issue May 24, 2018 · 3 comments
Open

Expose Data.Aeson.Encoding.Builder #644

alexbiehl opened this issue May 24, 2018 · 3 comments

Comments

@alexbiehl
Copy link
Member

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

"<some integer>_<day>": ... 

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:

     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.

@alexbiehl
Copy link
Member Author

(Or in general allow efficient encoding of this composite keys)

@bergmark
Copy link
Collaborator

bergmark commented Jul 6, 2018

Hey, sorry I missed this!

Exporting this in some way sounds good. I wonder if the module should be suffixed with Unsafe or Internal?

@gridaphobe
Copy link

It might be nice to expose the date/time encoders as a separate package like you did with the parsers. Perhaps iso8601-builder?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants