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

RFC: Object parser #564

Open
wants to merge 6 commits into
base: master
from

Conversation

Projects
None yet
1 participant
@phadej
Copy link
Contributor

phadej commented Jul 13, 2017

An applicative ObjectParser letting us make "strict" object parsers. cc @hvr

Performance is slightly degraded, as you can suspect:

screenshot from 2017-07-13 16-22-16

OTOH in case of missing / extra keys parser will fail early.


Motivation: for the TokenStream parser #560 such interface would be needed. The objectField could be a member of new class:

BTW, why parseJSON :: Value -> Parser a and not parseJSON :: Parser a, where

 newtype Parser a = Parser {
       runParser :: forall f r.
                    JSONPath
+                -> Value
                 -> Failure f r
                 -> Success a f r
                 -> f r
     }

(Probably because of manual instances, i.e. not using combinators like withObject)

-- | "dual" of 'KeyValue'
class OP p op | p -> op | op -> p where
    objectField :: Text -> p a -> op a
    runObjectParser :: String -> op a -> p a

instance OP Parser ObjectParaser where
    ... 

EDIT: if aeson is a wrong place for this, I'll add it to aeson-extra.

TODO:

  • documentation
  • tests
  • generics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment