waargonaut-0.8.0.1: JSON wrangling

Safe HaskellNone
LanguageHaskell2010

Waargonaut.Types.JObject

Contents

Description

Types and functions for handling our representation of a JSON object.

Synopsis

Object Type

newtype JObject ws a Source #

The representation of a JSON object.

The JSON RFC8259 indicates that names within an object "should" be unique. But the standard does not enforce this, leaving it to the various implementations to decide how to handle it.

As there are multiple possibilities for deciding which key to use when enforcing uniqueness, Waargonaut accepts duplicate keys, allowing you to decide how to handle it.

This type is the "list of tuples of key and value" structure, as such it is a wrapper around the CommaSeparated data type.

Constructors

JObject (CommaSeparated ws (JAssoc ws a)) 
Instances
Bifunctor JObject Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

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

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

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

Bitraversable JObject Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

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

Bifoldable JObject Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

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

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

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

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

Functor (JObject ws) Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

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

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

Foldable (JObject ws) Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

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

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

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

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

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

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

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

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

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

null :: JObject ws a -> Bool #

length :: JObject ws a -> Int #

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

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

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

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

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

Traversable (JObject ws) Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

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

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

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

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

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

Defined in Waargonaut.Types.JObject

Methods

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

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

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

Defined in Waargonaut.Types.JObject

Methods

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

show :: JObject ws a -> String #

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

(Semigroup ws, Monoid ws) => Semigroup (JObject ws a) Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

(<>) :: JObject ws a -> JObject ws a -> JObject ws a #

sconcat :: NonEmpty (JObject ws a) -> JObject ws a #

stimes :: Integral b => b -> JObject ws a -> JObject ws a #

(Semigroup ws, Monoid ws) => Monoid (JObject ws a) Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

mempty :: JObject ws a #

mappend :: JObject ws a -> JObject ws a -> JObject ws a #

mconcat :: [JObject ws a] -> JObject ws 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 #

Monoid ws => Ixed (JObject ws a) Source #

Without having an obviously correct "first" or "last" decision on which JString key is the "right" one to use, a JObject can only be indexed by a numeric value.

Instance details

Defined in Waargonaut.Types.JObject

Methods

ix :: Index (JObject ws a) -> Traversal' (JObject ws a) (IxValue (JObject ws a)) #

Wrapped (JObject ws a) Source # 
Instance details

Defined in Waargonaut.Types.JObject

Associated Types

type Unwrapped (JObject ws a) :: Type #

Methods

_Wrapped' :: Iso' (JObject ws a) (Unwrapped (JObject ws a)) #

(Semigroup ws, Monoid ws) => AsEmpty (JObject ws a) Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

_Empty :: Prism' (JObject ws a) () #

JObject ws a ~ t => Rewrapped (JObject ws a) t Source # 
Instance details

Defined in Waargonaut.Types.JObject

HasJObject (JObject ws a) ws a Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

jObject :: Lens' (JObject ws a) (JObject ws a) Source #

type Index (JObject ws a) Source # 
Instance details

Defined in Waargonaut.Types.JObject

type Index (JObject ws a) = Int
type IxValue (JObject ws a) Source # 
Instance details

Defined in Waargonaut.Types.JObject

type IxValue (JObject ws a) = a
type Unwrapped (JObject ws a) Source # 
Instance details

Defined in Waargonaut.Types.JObject

type Unwrapped (JObject ws a) = CommaSeparated ws (JAssoc ws a)

class HasJObject c ws a | c -> ws a where Source #

Type class to represent something that has a JObject within it.

Methods

jObject :: Lens' c (JObject ws a) Source #

Instances
HasJObject (JObject ws a) ws a Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

jObject :: Lens' (JObject ws a) (JObject ws a) Source #

Key/value pair type

data JAssoc ws a Source #

This type represents the key:value pair inside of a JSON object.

It is built like this so that we can preserve any whitespace information that may surround it.

Instances
Bifunctor JAssoc Source # 
Instance details

Defined in Waargonaut.Types.JObject.JAssoc

Methods

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

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

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

Bitraversable JAssoc Source # 
Instance details

Defined in Waargonaut.Types.JObject.JAssoc

Methods

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

Bifoldable JAssoc Source # 
Instance details

Defined in Waargonaut.Types.JObject.JAssoc

Methods

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

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

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

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

Functor (JAssoc ws) Source # 
Instance details

Defined in Waargonaut.Types.JObject.JAssoc

Methods

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

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

Foldable (JAssoc ws) Source # 
Instance details

Defined in Waargonaut.Types.JObject.JAssoc

Methods

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

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

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

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

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

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

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

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

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

null :: JAssoc ws a -> Bool #

length :: JAssoc ws a -> Int #

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

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

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

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

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

Traversable (JAssoc ws) Source # 
Instance details

Defined in Waargonaut.Types.JObject.JAssoc

Methods

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

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

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

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

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

Defined in Waargonaut.Types.JObject.JAssoc

Methods

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

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

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

Defined in Waargonaut.Types.JObject.JAssoc

Methods

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

show :: JAssoc ws a -> String #

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

HasJAssoc (JAssoc ws a) ws a Source # 
Instance details

Defined in Waargonaut.Types.JObject.JAssoc

class HasJAssoc c ws a | c -> ws a where Source #

This class allows you to write connective lenses for other data structures that may contain a JAssoc.

Minimal complete definition

jAssoc

Map-like object representation

data MapLikeObj ws a Source #

This is a newtype around our JObject for when we want to use the "map-like" representation of our JSON object. This data type will enforce that the first key found is treated as the desired element, and all subsequent occurrences of that key are discarded.

Instances
Bifunctor MapLikeObj Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

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

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

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

Bitraversable MapLikeObj Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

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

Bifoldable MapLikeObj Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

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

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

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

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

Functor (MapLikeObj ws) Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

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

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

Foldable (MapLikeObj ws) Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

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

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

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

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

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

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

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

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

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

null :: MapLikeObj ws a -> Bool #

length :: MapLikeObj ws a -> Int #

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

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

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

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

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

Traversable (MapLikeObj ws) Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

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

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

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

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

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

Defined in Waargonaut.Types.JObject

Methods

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

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

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

Defined in Waargonaut.Types.JObject

Methods

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

show :: MapLikeObj ws a -> String #

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

Monoid ws => Ixed (MapLikeObj ws a) Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

ix :: Index (MapLikeObj ws a) -> Traversal' (MapLikeObj ws a) (IxValue (MapLikeObj ws a)) #

Monoid ws => At (MapLikeObj ws a) Source #

Unlike JObject this type has an opinionated stance on which key is the "correct" one, so we're able to have an At instance.

Instance details

Defined in Waargonaut.Types.JObject

Methods

at :: Index (MapLikeObj ws a) -> Lens' (MapLikeObj ws a) (Maybe (IxValue (MapLikeObj ws a))) #

Wrapped (MapLikeObj ws a) Source # 
Instance details

Defined in Waargonaut.Types.JObject

Associated Types

type Unwrapped (MapLikeObj ws a) :: Type #

Methods

_Wrapped' :: Iso' (MapLikeObj ws a) (Unwrapped (MapLikeObj ws a)) #

(Monoid ws, Semigroup ws) => AsEmpty (MapLikeObj ws a) Source # 
Instance details

Defined in Waargonaut.Types.JObject

Methods

_Empty :: Prism' (MapLikeObj ws a) () #

MapLikeObj ws a ~ t => Rewrapped (MapLikeObj ws a) t Source # 
Instance details

Defined in Waargonaut.Types.JObject

type Index (MapLikeObj ws a) Source # 
Instance details

Defined in Waargonaut.Types.JObject

type Index (MapLikeObj ws a) = Text
type IxValue (MapLikeObj ws a) Source # 
Instance details

Defined in Waargonaut.Types.JObject

type IxValue (MapLikeObj ws a) = a
type Unwrapped (MapLikeObj ws a) Source # 
Instance details

Defined in Waargonaut.Types.JObject

type Unwrapped (MapLikeObj ws a) = JObject ws a

toMapLikeObj :: (Semigroup ws, Monoid ws) => JObject ws a -> (MapLikeObj ws a, [JAssoc ws a]) Source #

Take a JObject and produce a MapLikeObj where the first key is considered the unique value. Subsequence occurrences of that key and it's value are collected and returned as a list.

fromMapLikeObj :: MapLikeObj ws a -> JObject ws a Source #

Access the underlying JObject.

_MapLikeObj :: (Semigroup ws, Monoid ws) => Prism' (JObject ws a) (MapLikeObj ws a) Source #

Prism for working with a JObject as a MapLikeObj. This optic will keep the first unique key on a given JObject and this information is not recoverable. If you want to create a MapLikeObj from a JObject and keep what is removed, then use the toMapLikeObj function.

Parser

parseJObject :: (Monad f, CharParsing f) => f ws -> f a -> f (JObject ws a) Source #

>>> testparse (parseJObject parseWhitespace parseWaargonaut) "{\"foo\":null }"
Right (JObject (CommaSeparated (WS []) (Just (Elems {_elemsElems = [], _elemsLast = Elem {_elemVal = JAssoc {_jsonAssocKey = JString' [UnescapedJChar (Unescaped 'f'),UnescapedJChar (Unescaped 'o'),UnescapedJChar (Unescaped 'o')], _jsonAssocKeyTrailingWS = WS [], _jsonAssocValPreceedingWS = WS [], _jsonAssocVal = Json (JNull (WS [Space]))}, _elemTrailing = Nothing}}))))
>>> testparse (parseJObject parseWhitespace parseWaargonaut) "{\"foo\":null, }"
Right (JObject (CommaSeparated (WS []) (Just (Elems {_elemsElems = [], _elemsLast = Elem {_elemVal = JAssoc {_jsonAssocKey = JString' [UnescapedJChar (Unescaped 'f'),UnescapedJChar (Unescaped 'o'),UnescapedJChar (Unescaped 'o')], _jsonAssocKeyTrailingWS = WS [], _jsonAssocValPreceedingWS = WS [], _jsonAssocVal = Json (JNull (WS []))}, _elemTrailing = Just (Comma,WS [Space])}}))))