Safe Haskell | None |
---|---|
Language | Haskell98 |
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.
- 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
- (.=) :: ToJSON a => Text -> a -> Pair
- (.:) :: 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 Value :: *
data Parser a :: * -> *
data ParseException Source
prettyPrintParseException :: ParseException -> String Source
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:
AesonException "The key \"foo\" was not found"
It looks more pleasant to print:
Aeson exception: The key "foo" was not found
Since 0.8.11
data YamlException Source
YamlException String | |
YamlParseException | problem, context, index, position line, position column |
The pointer position
Constructors and accessors
Parsing
parseMonad :: Monad m => (a -> Parser b) -> a -> m b Source
parseEither :: (a -> Parser b) -> a -> Either String b
parseMaybe :: (a -> Parser b) -> a -> Maybe b
Classes
class ToJSON a where
Nothing
class FromJSON a where
Nothing
Encoding/decoding
encode :: ToJSON a => a -> ByteString Source
encodeFile :: ToJSON a => FilePath -> a -> IO () Source
decode :: FromJSON a => ByteString -> Maybe a Source
Better error information
decodeEither :: FromJSON a => ByteString -> Either String a Source
decodeEither' :: FromJSON a => ByteString -> Either ParseException a Source
More helpful version of decodeEither
which returns the YamlException
.
Since 0.8.3
decodeFileEither :: FromJSON a => FilePath -> IO (Either ParseException a) Source
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)) Source