Maintainer | Jiri Marsicek <jiri.marsicek@gmail.com> |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Hiearchical prefixing of JSON objects from Aeson
Please see examples for understanding what does it mean.
Examples
usage of prefix
Basic
{ "a": { "b": 1 } }
results in { "a": { "a.b": 2 }
{ "a": { "b": { "c": 1 } } }
results in { "a": { "a.b": { "a.b.c": 1 } } }
Arrays
{ "a": [ { "b": 1 }, { "b": 2 } ] }
is not changed
- Arrays don't inherit the prefix from their parent keys by default
With optionPreservePrefix
set to True
{ "a": [ { "b": 1 }, { "b": 2 } ] }
results in { "a": [ { "a.b": 1 }, { "a.b": 2 } ] }
With optionPrefix
set to "prefix"
{ "a": 1 }
results in { "prefix.a": 1 }
- This affects only keys in top level object.
- If array is top level, it doesn't take effect unless you set
optionPreservePrefix
toTrue
With optionSeparator
set to "~"
{ "a": { "b": 1 } }
results in { "a": { "a~b": 2 } }
- prefix :: forall m. (Monad m, MonadReader Options m) => Value -> m Value
- data Options = Options {}
- type Prefix = Maybe Text
- type Separator = Text
- defaultOptions :: Options
- type Pair = (Text, Value)
- prefixKey :: forall m. (Monad m, MonadReader Options m) => Text -> m Text
- prefixPair :: forall m. (Monad m, MonadReader Options m) => Pair -> m Pair
- withPrefix :: Prefix -> Options -> Options
- withoutPrefix :: Options -> Options
Documentation
Options
Options | |
|
defaultOptions :: Options Source #
Default options
optionPreservePrefix
set toFalse
optionSeparator
set to "."optionPrefix
set toNothing
Utility functions and types
prefixKey :: forall m. (Monad m, MonadReader Options m) => Text -> m Text Source #
Prefixes text with prefix if defined in options, a separator from options is used to delimit prefix and text
prefixPair :: forall m. (Monad m, MonadReader Options m) => Pair -> m Pair Source #
Prefixes identifier (first in pair), this prefixed identifier is used as a prefix for value (second in pair)
withoutPrefix :: Options -> Options Source #
Change options to not use any prefix