waargonaut-0.8.0.1: JSON wrangling

Safe HaskellNone
LanguageHaskell2010

Waargonaut.Types.Json

Contents

Description

Top level types and functions for Waargonaut Json types.

Synopsis

Inner JSON types

data JType ws a Source #

Individual JSON Types and their trailing whitespace.

Constructors

JNull ws 
JBool Bool ws 
JNum JNumber ws 
JStr JString ws 
JArr (JArray ws a) ws 
JObj (JObject ws a) ws 
Instances
Bifunctor JType Source # 
Instance details

Defined in Waargonaut.Types.Json

Methods

bimap :: (a -> b) -> (c -> d) -> JType a c -> JType b d #

first :: (a -> b) -> JType a c -> JType b c #

second :: (b -> c) -> JType a b -> JType a c #

Bitraversable JType Source # 
Instance details

Defined in Waargonaut.Types.Json

Methods

bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> JType a b -> f (JType c d) #

Bifoldable JType Source # 
Instance details

Defined in Waargonaut.Types.Json

Methods

bifold :: Monoid m => JType m m -> m #

bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> JType a b -> m #

bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> JType a b -> c #

bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> JType a b -> c #

Functor (JType ws) Source # 
Instance details

Defined in Waargonaut.Types.Json

Methods

fmap :: (a -> b) -> JType ws a -> JType ws b #

(<$) :: a -> JType ws b -> JType ws a #

Foldable (JType ws) Source # 
Instance details

Defined in Waargonaut.Types.Json

Methods

fold :: Monoid m => JType ws m -> m #

foldMap :: Monoid m => (a -> m) -> JType ws a -> m #

foldr :: (a -> b -> b) -> b -> JType ws a -> b #

foldr' :: (a -> b -> b) -> b -> JType ws a -> b #

foldl :: (b -> a -> b) -> b -> JType ws a -> b #

foldl' :: (b -> a -> b) -> b -> JType ws a -> b #

foldr1 :: (a -> a -> a) -> JType ws a -> a #

foldl1 :: (a -> a -> a) -> JType ws a -> a #

toList :: JType ws a -> [a] #

null :: JType ws a -> Bool #

length :: JType ws a -> Int #

elem :: Eq a => a -> JType ws a -> Bool #

maximum :: Ord a => JType ws a -> a #

minimum :: Ord a => JType ws a -> a #

sum :: Num a => JType ws a -> a #

product :: Num a => JType ws a -> a #

Traversable (JType ws) Source # 
Instance details

Defined in Waargonaut.Types.Json

Methods

traverse :: Applicative f => (a -> f b) -> JType ws a -> f (JType ws b) #

sequenceA :: Applicative f => JType ws (f a) -> f (JType ws a) #

mapM :: Monad m => (a -> m b) -> JType ws a -> m (JType ws b) #

sequence :: Monad m => JType ws (m a) -> m (JType ws a) #

(Eq ws, Eq a) => Eq (JType ws a) Source # 
Instance details

Defined in Waargonaut.Types.Json

Methods

(==) :: JType ws a -> JType ws a -> Bool #

(/=) :: JType ws a -> JType ws a -> Bool #

(Show ws, Show a) => Show (JType ws a) Source # 
Instance details

Defined in Waargonaut.Types.Json

Methods

showsPrec :: Int -> JType ws a -> ShowS #

show :: JType ws a -> String #

showList :: [JType ws a] -> ShowS #

AsJType (JType ws a) ws a Source # 
Instance details

Defined in Waargonaut.Types.Json

Methods

_JType :: Prism' (JType ws a) (JType ws a) Source #

_JNull :: Prism' (JType ws a) ws Source #

_JBool :: Prism' (JType ws a) (Bool, ws) Source #

_JNum :: Prism' (JType ws a) (JNumber, ws) Source #

_JStr :: Prism' (JType ws a) (JString, ws) Source #

_JArr :: Prism' (JType ws a) (JArray ws a, ws) Source #

_JObj :: Prism' (JType ws a) (JObject ws a, ws) Source #

class AsJType r ws a | r -> ws a where Source #

Typeclass for things that can represent a JType

Minimal complete definition

_JType

Methods

_JType :: Prism' r (JType ws a) Source #

_JNull :: Prism' r ws Source #

_JBool :: Prism' r (Bool, ws) Source #

_JNum :: Prism' r (JNumber, ws) Source #

_JStr :: Prism' r (JString, ws) Source #

_JArr :: Prism' r (JArray ws a, ws) Source #

_JObj :: Prism' r (JObject ws a, ws) Source #

Instances
AsJType Json WS Json Source #

Json is comprised of the different JType types.

Instance details

Defined in Waargonaut.Types.Json

AsJType (JType ws a) ws a Source # 
Instance details

Defined in Waargonaut.Types.Json

Methods

_JType :: Prism' (JType ws a) (JType ws a) Source #

_JNull :: Prism' (JType ws a) ws Source #

_JBool :: Prism' (JType ws a) (Bool, ws) Source #

_JNum :: Prism' (JType ws a) (JNumber, ws) Source #

_JStr :: Prism' (JType ws a) (JString, ws) Source #

_JArr :: Prism' (JType ws a) (JArray ws a, ws) Source #

_JObj :: Prism' (JType ws a) (JObject ws a, ws) Source #

Top level JSON type

newtype Json Source #

Top level Json type, we specialise the whitespace to WS and the digit type to Digit. Also defining that our structures can recursively only contain Json types.

Constructors

Json (JType WS Json) 
Instances
Eq Json Source # 
Instance details

Defined in Waargonaut.Types.Json

Methods

(==) :: Json -> Json -> Bool #

(/=) :: Json -> Json -> Bool #

Show Json Source # 
Instance details

Defined in Waargonaut.Types.Json

Methods

showsPrec :: Int -> Json -> ShowS #

show :: Json -> String #

showList :: [Json] -> ShowS #

Wrapped Json Source # 
Instance details

Defined in Waargonaut.Types.Json

Associated Types

type Unwrapped Json :: Type #

Json ~ t => Rewrapped Json t Source # 
Instance details

Defined in Waargonaut.Types.Json

AsJType Json WS Json Source #

Json is comprised of the different JType types.

Instance details

Defined in Waargonaut.Types.Json

JsonDecode (t :: k) Json Source # 
Instance details

Defined in Waargonaut.Generic

Methods

mkDecoder :: Monad f => Tagged t (Decoder f Json) Source #

JsonEncode (t :: k) Json Source # 
Instance details

Defined in Waargonaut.Generic

Monad f => MonadReader ParseFn (DecodeResult f) Source # 
Instance details

Defined in Waargonaut.Decode.Types

Methods

ask :: DecodeResult f ParseFn #

local :: (ParseFn -> ParseFn) -> DecodeResult f a -> DecodeResult f a #

reader :: (ParseFn -> a) -> DecodeResult f a #

Applicative f => Divisible (EncoderFns (JObject WS Json) f) Source # 
Instance details

Defined in Waargonaut.Encode.Types

Methods

divide :: (a -> (b, c)) -> EncoderFns (JObject WS Json) f b -> EncoderFns (JObject WS Json) f c -> EncoderFns (JObject WS Json) f a #

conquer :: EncoderFns (JObject WS Json) f a #

Applicative f => Decidable (EncoderFns (JObject WS Json) f) Source # 
Instance details

Defined in Waargonaut.Encode.Types

Methods

lose :: (a -> Void) -> EncoderFns (JObject WS Json) f a #

choose :: (a -> Either b c) -> EncoderFns (JObject WS Json) f b -> EncoderFns (JObject WS Json) f c -> EncoderFns (JObject WS Json) f a #

type Unwrapped Json Source # 
Instance details

Defined in Waargonaut.Types.Json

Parser

parseWaargonaut :: (Monad f, CharParsing f) => f Json Source #

Parse to a Json value, keeping all of the information about the leading and trailing whitespace.

Traversals

jsonTraversal :: Traversal' Json Json Source #

Ignoring whitespace, traverse a Json structure.

jsonWSTraversal :: Traversal Json Json WS WS Source #

Traverse the trailing whitespace of this Json structure.

jtypeTraversal :: Traversal (JType ws a) (JType ws a') a a' Source #

Traverse the possible values of a JType, skipping whitespace.

jtypeWSTraversal :: Traversal (JType ws a) (JType ws' a) ws ws' Source #

Traverse all of the whitespace of this Json structure and every element in the tree.

Optics

oat :: (AsJType r ws a, Semigroup ws, Monoid ws) => Text -> Traversal' r (Maybe a) Source #

A Traversal' over the a at the given Text key on a JSON object.

>>> E.simplePureEncodeTextNoSpaces E.json (obj & oat "c" ?~ E.asJson' E.int 33)
"{\"c\":33,\"a\":33,\"b\":\"Fred\"}"
>>> E.simplePureEncodeTextNoSpaces E.json (obj & oat "d" ?~ E.asJson' E.text "sally")
"{\"d\":\"sally\",\"a\":33,\"b\":\"Fred\"}"

oix :: (Semigroup ws, Monoid ws, AsJType r ws a) => Int -> Traversal' r a Source #

A Traversal' over the a at the given Int position in a JSON object.

>>> E.simplePureEncodeTextNoSpaces E.json (obj & oix 0 .~ E.asJson' E.int 1)
"{\"a\":1,\"b\":\"Fred\"}"
>>> E.simplePureEncodeTextNoSpaces E.json (obj & oix 1 .~ E.asJson' E.text "sally")
"{\"a\":33,\"b\":\"sally\"}"

aix :: (AsJType r ws a, Semigroup ws, Monoid ws) => Int -> Traversal' r a Source #

A Traversal' over the a at the given Int position in a JSON array.

>>> E.simplePureEncodeTextNoSpaces E.json ((E.asJson' (E.list E.int) [1,2,3]) & aix 0 .~ E.asJson' E.int 99)
"[99,2,3]"
>>> E.simplePureEncodeTextNoSpaces E.json ((E.asJson' (E.list E.int) [1,2,3]) & aix 2 .~ E.asJson' E.int 44)
"[1,2,44]"