conferer-source-json-0.4.0.1: conferer's source for reading json files

Safe HaskellNone
LanguageHaskell2010

Conferer.Source.JSON

Contents

Synopsis

How to use this source

As any other source you can add it to a config using the addSource function. There are a couple of oddities that come from supporting many different sources which do not support numbers, arrays or objects nativelly

import Conferer
import Conferer.Source.JSON (mkJsonSource)

main = do
  config <-
    defaultConfig "awesomeapp"
    & addSource mkJsonSource
  warpSettings <- getFromConfig "warp" config
  runSettings warpSettings application

This will result on a source that upon starting looks the file config/{.env}.json in the current directory and uses it to provide config keys.

TODO Describe how we transform json into key value strings

mkJsonSource :: SourceCreator Source #

Default SourceCreator which usese files with config/{env}.json template, if the file is not present it will behave like the null source (it has no keys) but if the file doesn't have valid json it will throw an error

mkJsonSource' :: Value -> SourceCreator Source #

Just like mkJsonSource but accepts the json value as a parameter

Internal utility functions

These may be useful for someone but are subject to change at any point so use with care

traverseJSON :: Key -> Value -> Maybe Text Source #

Traverse a Value using a Key to get a value for conferer (Text).

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}} == Nothing
traverseJSON "1" [false, true] == Just "true"
traverseJSON "0.a" [{a: "hi"}] == Just "hi"
traverseJSON "0" [] == Nothing

resultToMaybe :: Result a -> Maybe a Source #

Because we use an old version of aeson