roundtrip-aeson-0.2.0.0: Un-/parse JSON with roundtrip invertible syntax definitions.

Safe HaskellNone
LanguageHaskell2010

Data.Aeson.Roundtrip

Contents

Synopsis

Parser/Builder

newtype JsonParser a Source

An implementation of JsonSyntax which deconstructs JSON values.

Constructors

JsonParser 

Fields

runParser :: Value -> Either String a
 

newtype JsonBuilder a Source

An implementation of JsonSyntax which constructs JSON values.

Constructors

JsonBuilder 

Fields

runBuilder :: a -> Either String Value
 

Combinators

is :: (JsonSyntax s, Eq a) => s a -> a -> s () Source

Ensure that a value a is "produced" or "consumed".

This is intended to be used infix in conjunction with *> and <*

wat :: JsonSyntax s => a -> s a Source

With Arbitrary Thing: Given a thing, ensure that it is always included on the way "back" from JSON, but never ends up in the JSON document.

This is almost like pure, going one way.

Syntaxes

jsonField Source

Arguments

:: JsonSyntax s 
=> Text

Key to lookup/insert

-> s v

Sub-parser

-> s v 

Un-/parse from within a field in a JSON object.

jsonString :: JsonSyntax s => s Text Source

Un-/parse a string JSON value.

jsonBool :: JsonSyntax s => s Bool Source

Un-/parse a boolean JSON value.

jsonNumber :: JsonSyntax s => s Scientific Source

Un-/parse a number JSON value.

jsonIntegral :: (Integral a, JsonSyntax s) => s a Source

Un-/parse an integral number JSON value.

jsonRealFloat :: (RealFloat a, JsonSyntax s) => s a Source

Un-/parse a floating number JSON value.

Lenses, Prisms, and Isomorphisms.

demote :: String -> Prism' a b -> Iso a b Source

Demote a lens Prism to a partial Iso.

This involves strapping a _Just onto the review as a prism is slightly "stronger" than an Iso anyway. Bear in mind that this is not a lens iso but a RoundTrip iso.

This also works on lens isos, you can imagine this as :

demote :: L.Iso' a b -> Iso a b

demoteLR :: (Show a, Show b) => String -> Prism' a b -> Iso a b Source

Demote something with show instances for better messages.

demoteL :: Show a => String -> Prism' a b -> Iso a b Source

demoteR :: Show b => String -> Prism' a b -> Iso a b Source

JSON Syntax

class Syntax s => JsonSyntax s where Source

Parse and unparse JSON values.

Methods

runSub :: s v -> s Value -> s v Source

Run a parser over some other parser.

This can be used to, e.g., traverse the fields of an Object constructor and parse the result.

value :: s Value Source

Parse any JSON value.