Safe Haskell | None |
---|---|
Language | Haskell2010 |
Types and functions for handling our representation of a JSON object.
Synopsis
- newtype JObject ws a = JObject (CommaSeparated ws (JAssoc ws a))
- class HasJObject c ws a | c -> ws a where
- data JAssoc ws a = JAssoc {
- _jsonAssocKey :: JString
- _jsonAssocKeyTrailingWS :: ws
- _jsonAssocValPreceedingWS :: ws
- _jsonAssocVal :: a
- class HasJAssoc c ws a | c -> ws a where
- jAssoc :: Lens' c (JAssoc ws a)
- jsonAssocKey :: Lens' c JString
- jsonAssocKeyTrailingWS :: Lens' c ws
- jsonAssocVal :: Lens' c a
- jsonAssocValPreceedingWS :: Lens' c ws
- data MapLikeObj ws a
- toMapLikeObj :: (Semigroup ws, Monoid ws) => JObject ws a -> (MapLikeObj ws a, [JAssoc ws a])
- fromMapLikeObj :: MapLikeObj ws a -> JObject ws a
- _MapLikeObj :: (Semigroup ws, Monoid ws) => Prism' (JObject ws a) (MapLikeObj ws a)
- parseJObject :: (Monad f, CharParsing f) => f ws -> f a -> f (JObject ws a)
Object Type
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.
JObject (CommaSeparated ws (JAssoc ws a)) |
Instances
Bitraversable JObject Source # | |
Defined in Waargonaut.Types.JObject bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> JObject a b -> f (JObject c d) # | |
Bifoldable JObject Source # | |
Bifunctor JObject Source # | |
Functor (JObject ws) Source # | |
Foldable (JObject ws) Source # | |
Defined in Waargonaut.Types.JObject fold :: Monoid m => JObject ws m -> m # foldMap :: Monoid m => (a -> m) -> JObject ws a -> 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 # | |
Traversable (JObject ws) Source # | |
Defined in Waargonaut.Types.JObject | |
(Eq ws, Eq a) => Eq (JObject ws a) Source # | |
(Show ws, Show a) => Show (JObject ws a) Source # | |
(Semigroup ws, Monoid ws) => Semigroup (JObject ws a) Source # | |
(Semigroup ws, Monoid ws) => Monoid (JObject ws a) Source # | |
Monoid ws => Ixed (JObject ws a) Source # | Without having an obviously correct "first" or "last" decision on which
|
Defined in Waargonaut.Types.JObject | |
(Semigroup ws, Monoid ws) => AsEmpty (JObject ws a) Source # | |
Defined in Waargonaut.Types.JObject | |
Wrapped (JObject ws a) Source # | |
Defined in Waargonaut.Types.JObject type Unwrapped (JObject ws a) | |
Applicative f => Decidable (EncoderFns (JObject WS Json) f) | |
Defined in Waargonaut.Encode.Types 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 | |
Applicative f => Divisible (EncoderFns (JObject WS Json) f) | |
Defined in Waargonaut.Encode.Types 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 | |
JObject ws a ~ t => Rewrapped (JObject ws a) t Source # | |
Defined in Waargonaut.Types.JObject | |
HasJObject (JObject ws a) ws a Source # | |
type Index (JObject ws a) Source # | |
Defined in Waargonaut.Types.JObject | |
type IxValue (JObject ws a) Source # | |
Defined in Waargonaut.Types.JObject type IxValue (JObject ws a) = a | |
type Unwrapped (JObject ws a) Source # | |
Defined in Waargonaut.Types.JObject |
class HasJObject c ws a | c -> ws a where Source #
Type class to represent something that has a JObject
within it.
Instances
HasJObject (JObject ws a) ws a Source # | |
Key/value pair type
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.
JAssoc | |
|
Instances
Bitraversable JAssoc Source # | |
Defined in Waargonaut.Types.JObject.JAssoc bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> JAssoc a b -> f (JAssoc c d) # | |
Bifoldable JAssoc Source # | |
Bifunctor JAssoc Source # | |
Functor (JAssoc ws) Source # | |
Foldable (JAssoc ws) Source # | |
Defined in Waargonaut.Types.JObject.JAssoc fold :: Monoid m => JAssoc ws m -> m # foldMap :: Monoid m => (a -> m) -> JAssoc ws a -> 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] # 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 # | |
Traversable (JAssoc ws) Source # | |
Defined in Waargonaut.Types.JObject.JAssoc | |
(Eq ws, Eq a) => Eq (JAssoc ws a) Source # | |
(Show ws, Show a) => Show (JAssoc ws a) Source # | |
HasJAssoc (JAssoc ws a) ws a Source # | |
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
.
jAssoc :: Lens' c (JAssoc ws a) Source #
jsonAssocKey :: Lens' c JString Source #
jsonAssocKeyTrailingWS :: Lens' c ws Source #
jsonAssocVal :: Lens' c a Source #
jsonAssocValPreceedingWS :: Lens' c ws Source #
Instances
HasJAssoc (JAssoc ws a) ws a Source # | |
Defined in Waargonaut.Types.JObject.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
Bitraversable MapLikeObj Source # | |
Defined in Waargonaut.Types.JObject bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> MapLikeObj a b -> f (MapLikeObj c d) # | |
Bifoldable MapLikeObj Source # | |
Defined in Waargonaut.Types.JObject 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 # | |
Bifunctor MapLikeObj Source # | |
Defined in Waargonaut.Types.JObject 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 # | |
Functor (MapLikeObj ws) Source # | |
Defined in Waargonaut.Types.JObject fmap :: (a -> b) -> MapLikeObj ws a -> MapLikeObj ws b # (<$) :: a -> MapLikeObj ws b -> MapLikeObj ws a # | |
Foldable (MapLikeObj ws) Source # | |
Defined in Waargonaut.Types.JObject fold :: Monoid m => MapLikeObj ws m -> m # foldMap :: Monoid m => (a -> m) -> MapLikeObj ws a -> 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 # | |
Defined in Waargonaut.Types.JObject 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 # | |
Defined in Waargonaut.Types.JObject (==) :: MapLikeObj ws a -> MapLikeObj ws a -> Bool # (/=) :: MapLikeObj ws a -> MapLikeObj ws a -> Bool # | |
(Show ws, Show a) => Show (MapLikeObj ws a) Source # | |
Defined in Waargonaut.Types.JObject showsPrec :: Int -> MapLikeObj ws a -> ShowS # show :: MapLikeObj ws a -> String # showList :: [MapLikeObj ws a] -> ShowS # | |
Monoid ws => At (MapLikeObj ws a) Source # | Unlike |
Defined in Waargonaut.Types.JObject at :: Index (MapLikeObj ws a) -> Lens' (MapLikeObj ws a) (Maybe (IxValue (MapLikeObj ws a))) | |
Monoid ws => Ixed (MapLikeObj ws a) Source # | |
Defined in Waargonaut.Types.JObject ix :: Index (MapLikeObj ws a) -> Traversal' (MapLikeObj ws a) (IxValue (MapLikeObj ws a)) | |
(Monoid ws, Semigroup ws) => AsEmpty (MapLikeObj ws a) Source # | |
Defined in Waargonaut.Types.JObject _Empty :: Prism' (MapLikeObj ws a) () | |
Wrapped (MapLikeObj ws a) Source # | |
Defined in Waargonaut.Types.JObject type Unwrapped (MapLikeObj ws a) _Wrapped' :: Iso' (MapLikeObj ws a) (Unwrapped (MapLikeObj ws a)) | |
MapLikeObj ws a ~ t => Rewrapped (MapLikeObj ws a) t Source # | |
Defined in Waargonaut.Types.JObject | |
type Index (MapLikeObj ws a) Source # | |
Defined in Waargonaut.Types.JObject | |
type IxValue (MapLikeObj ws a) Source # | |
Defined in Waargonaut.Types.JObject type IxValue (MapLikeObj ws a) = a | |
type Unwrapped (MapLikeObj ws a) Source # | |
Defined in Waargonaut.Types.JObject |
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])}}))))