Safe Haskell | None |
---|---|
Language | Haskell98 |
Data.Yaml
Contents
Description
Provides a high-level interface for processing YAML files.
This module reuses most of the infrastructure from the aeson
package.
This means that you can use all of the existing tools for JSON
processing for processing YAML files. As a result, much of the
documentation below mentions JSON; do not let that confuse you, it's
intentional.
For the most part, YAML content translates directly into JSON, and therefore there is very little data loss. If you need to deal with YAML more directly (e.g., directly deal with aliases), you should use the Text.Libyaml module instead.
For documentation on the aeson
types, functions, classes, and
operators, please see the Data.Aeson
module of the aeson
package.
Look in the examples directory of the source repository for some initial pointers on how to use this library.
- data Value :: *
- data Parser a :: * -> *
- type Object = HashMap Text Value
- type Array = Vector Value
- data ParseException
- prettyPrintParseException :: ParseException -> String
- data YamlException
- data YamlMark = YamlMark {}
- object :: [Pair] -> Value
- array :: [Value] -> Value
- (.=) :: KeyValue kv => forall v. ToJSON v => Text -> v -> kv
- (.:) :: FromJSON a => Object -> Text -> Parser a
- (.:?) :: FromJSON a => Object -> Text -> Parser (Maybe a)
- (.!=) :: Parser (Maybe a) -> a -> Parser a
- parseMonad :: Monad m => (a -> Parser b) -> a -> m b
- parseEither :: (a -> Parser b) -> a -> Either String b
- parseMaybe :: (a -> Parser b) -> a -> Maybe b
- class ToJSON a where
- class FromJSON a where
- encode :: ToJSON a => a -> ByteString
- encodeFile :: ToJSON a => FilePath -> a -> IO ()
- decode :: FromJSON a => ByteString -> Maybe a
- decodeFile :: FromJSON a => FilePath -> IO (Maybe a)
- decodeEither :: FromJSON a => ByteString -> Either String a
- decodeEither' :: FromJSON a => ByteString -> Either ParseException a
- decodeFileEither :: FromJSON a => FilePath -> IO (Either ParseException a)
- decodeHelper :: FromJSON a => Source Parse Event -> IO (Either ParseException (Either String a))
Types
data ParseException #
Constructors
NonScalarKey | |
UnknownAlias | |
Fields | |
UnexpectedEvent | |
InvalidYaml (Maybe YamlException) | |
AesonException String | |
OtherParseException SomeException | |
NonStringKeyAlias AnchorName Value | |
CyclicIncludes |
Instances
prettyPrintParseException :: ParseException -> String #
Alternative to show
to display a ParseException
on the screen.
Instead of displaying the data constructors applied to their arguments,
a more textual output is returned. For example, instead of printing:
InvalidYaml (Just (YamlParseException {yamlProblem = "did not find expected ',' or '}'", yamlContext = "while parsing a flow mapping", yamlProblemMark = YamlMark {yamlIndex = 42, yamlLine = 2, yamlColumn = 12}})))
It looks more pleasant to print:
YAML parse exception at line 2, column 12, while parsing a flow mapping: did not find expected ',' or '}'
Since 0.8.11
data YamlException #
Constructors
YamlException String | |
YamlParseException | problem, context, index, position line, position column |
Fields |
Instances
The pointer position
Constructors and accessors
Parsing
parseMonad :: Monad m => (a -> Parser b) -> a -> m b #
parseEither :: (a -> Parser b) -> a -> Either String b #
parseMaybe :: (a -> Parser b) -> a -> Maybe b #
Classes
Instances
Instances
Encoding/decoding
encode :: ToJSON a => a -> ByteString #
encodeFile :: ToJSON a => FilePath -> a -> IO () #
decode :: FromJSON a => ByteString -> Maybe a #
Better error information
decodeEither :: FromJSON a => ByteString -> Either String a #
decodeEither' :: FromJSON a => ByteString -> Either ParseException a #
More helpful version of decodeEither
which returns the YamlException
.
Since 0.8.3
decodeFileEither :: FromJSON a => FilePath -> IO (Either ParseException a) #
A version of decodeFile
which should not throw runtime exceptions.
Since 0.8.4
More control over decoding
decodeHelper :: FromJSON a => Source Parse Event -> IO (Either ParseException (Either String a)) #