-
Notifications
You must be signed in to change notification settings - Fork 324
Add handling of duplicate keys #714
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
Conversation
- This allows explicit handling of duplicate keys. - Also remove an outdated comment about the difference between the parsers value and json (they have been the same for a while).
Woohoo, a compiler bug on 7.6.3 - 7.10.3 https://travis-ci.org/bos/aeson/jobs/549001593 |
…f simplifier ticks
Cool, thanks! |
objectValues str val = do | ||
-- The object parser 'objectValues' is parameterized by the object constructor. | ||
-- See also 'jsonWith'. | ||
type HFromList = [(Text, Value)] -> Parser Object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd have Either String Object
as a return type. Parser
is "too big".
And actually wouldn't use a type synonym, hFromList
is confusing naming, mkObject
is what it is
EDIT: I see HFromList
is because of HashMap.fromList
, too far. mkObject
is a domain specific, thus better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I forgot we're in attoparsec's Parser
, not aeson's Parser
(which is closer to Either
). That's a fair point about the synonym, I'll remove it. Thanks for the review!
fmap (Array . Vector.fromList . ($ [])) . H.fromListWith (.) . (fmap . fmap) (:) | ||
|
||
-- | @'fromListNoDup' kvs@ fails if @kvs@ contains duplicate keys. | ||
parseListNoDup :: [(Text, Value)] -> Parser Object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
point in case: here the HFromList
is not used, so connecting the dots is difficult.
I'd remove the type alias.
Fixes #531.
This adds a parameterized parser
jsonWith
to let users decide what to do with objects with duplicate keys. A few common variants are also included.Benchmarks to guard against regression (using the aeson-parse benchmark) (no difference on GHC 8.6, 8.4, there seems to be a 2% slowdown on 8.2.2) https://gist.github.com/Lysxia/beb1aa201c79f576b94c509af7f0abfa