yaml-0.8.18.7: Support for parsing and rendering YAML documents.

Safe HaskellNone
LanguageHaskell98

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.

Synopsis

Types

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:

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 Source

Constructors

YamlException String 
YamlParseException

problem, context, index, position line, position column

data YamlMark Source

The pointer position

Constructors

YamlMark 

Fields

yamlIndex :: Int
 
yamlLine :: Int
 
yamlColumn :: Int
 

Instances

Constructors and accessors

object :: [Pair] -> 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

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

Minimal complete definition

Nothing

Methods

toJSON :: a -> Value

toEncoding :: a -> Encoding

class FromJSON a where

Minimal complete definition

Nothing

Methods

parseJSON :: Value -> Parser a

Encoding/decoding

encodeFile :: ToJSON a => FilePath -> a -> IO () Source

Better error information

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