Copyright | (c) 2019 Lucas David Traverso |
---|---|
License | MPL-2.0 |
Maintainer | Lucas David Traverso <lucas6246@gmail.com> |
Stability | stable |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Conferer.Source.Aeson
Description
Source for json config files using Aeson
Synopsis
- data JsonSource = JsonSource {}
- fromConfig :: Key -> SourceCreator
- fromFilePath :: FilePath -> SourceCreator
- fromFilePath' :: FilePath -> IO Source
- data JsonHasInvalidKeysError = JsonHasInvalidKeysError FilePath [RawKey]
- fromValue :: Value -> Source
- traverseJSON :: Key -> Value -> Maybe Value
- listKeysInJSON :: Value -> [Key]
- valueToText :: Value -> Maybe Text
- boolToString :: Bool -> Text
- resultToMaybe :: Result a -> Maybe a
- type RawKey = [Text]
- invalidJsonKeys :: Value -> [RawKey]
- allKeys :: Value -> [RawKey]
Documentation
data JsonSource Source #
Source
that read a config file as json and uses that value in a way that
makes sense for Conferer but doesn't respect json perfectly.
Constructors
JsonSource | |
Instances
Eq JsonSource Source # | |
Defined in Conferer.Source.Aeson | |
Show JsonSource Source # | |
Defined in Conferer.Source.Aeson Methods showsPrec :: Int -> JsonSource -> ShowS # show :: JsonSource -> String # showList :: [JsonSource] -> ShowS # | |
IsSource JsonSource Source # | |
Defined in Conferer.Source.Aeson Methods getKeyInSource :: JsonSource -> Key -> IO (Maybe Text) # getSubkeysInSource :: JsonSource -> Key -> IO [Key] # |
fromConfig :: Key -> SourceCreator Source #
Create a SourceCreator
which uses files with config/{env}.json
template and then uses fromFilePath
fromFilePath :: FilePath -> SourceCreator Source #
Create a SourceCreator
from a filepath
If the file is not present it will behave as if it had no keys.
If the file doesn't have valid json it will throw an error.
fromFilePath' :: FilePath -> IO Source Source #
Create a Source
from a filepath
If the file is not present it will behave as if it had no keys.
If the file doesn't have valid json it will throw an error.
data JsonHasInvalidKeysError Source #
Exception thrown from fromFilePath
when the json in the
parsed file has incorrect keys
Constructors
JsonHasInvalidKeysError FilePath [RawKey] |
Instances
Eq JsonHasInvalidKeysError Source # | |
Defined in Conferer.Source.Aeson Methods (==) :: JsonHasInvalidKeysError -> JsonHasInvalidKeysError -> Bool # (/=) :: JsonHasInvalidKeysError -> JsonHasInvalidKeysError -> Bool # | |
Show JsonHasInvalidKeysError Source # | |
Defined in Conferer.Source.Aeson Methods showsPrec :: Int -> JsonHasInvalidKeysError -> ShowS # show :: JsonHasInvalidKeysError -> String # showList :: [JsonHasInvalidKeysError] -> ShowS # | |
Exception JsonHasInvalidKeysError Source # | |
Defined in Conferer.Source.Aeson |
traverseJSON :: Key -> Value -> Maybe Value Source #
Traverse a Value
using a Key
to get a Value
.
This function can nest objects and arrays when keys are nested
traverseJSON
"a.b" {a: {b: 12}} == Just "12"traverseJSON
"a.b" {a: {b: false}} == Just "false"traverseJSON
"a" {a: {b: false}} == NothingtraverseJSON
"1" [false, true] == Just "true"traverseJSON
"0.a" [{a: "hi"}] == Just "hi"traverseJSON
"0" [] == Nothing
listKeysInJSON :: Value -> [Key] Source #
Get the list of available keys inside a json value
resultToMaybe :: Result a -> Maybe a Source #
Because we use an old version of aeson