Safe Haskell | None |
---|
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.
- data Value
- data Parser a
- type Object = HashMap Text Value
- type Array = Vector Value
- data ParseException
- = NonScalarKey
- | UnknownAlias { }
- | UnexpectedEvent { }
- | InvalidYaml (Maybe YamlException)
- | AesonException String
- | OtherParseException SomeException
- data YamlException
- = YamlException String
- | YamlParseException {
- yamlProblem :: String
- yamlContext :: String
- yamlProblemMark :: YamlMark
- data YamlMark = YamlMark {
- yamlIndex :: Int
- yamlLine :: Int
- yamlColumn :: Int
- 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
Constructors
NonScalarKey | |
UnknownAlias | |
Fields | |
UnexpectedEvent | |
InvalidYaml (Maybe YamlException) | |
AesonException String | |
OtherParseException SomeException |
Instances
Show ParseException | |
Typeable ParseException | |
Exception ParseException |
data YamlException
Constructors
YamlException String | |
YamlParseException | problem, context, index, position line, position column |
Fields
|
Instances
Show YamlException | |
Typeable YamlException | |
Exception YamlException |
data YamlMark
The pointer position
Constructors
YamlMark | |
Fields
|
Instances
Show YamlMark |
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
class ToJSON a where
Instances
ToJSON Bool | |
ToJSON Char | |
ToJSON Double | |
ToJSON Float | |
ToJSON Int | |
ToJSON Int8 | |
ToJSON Int16 | |
ToJSON Int32 | |
ToJSON Int64 | |
ToJSON Integer | |
ToJSON Word | |
ToJSON Word8 | |
ToJSON Word16 | |
ToJSON Word32 | |
ToJSON Word64 | |
ToJSON () | |
ToJSON ByteString | |
ToJSON ByteString | |
ToJSON Text | |
ToJSON Number | |
ToJSON Text | |
ToJSON Value | |
ToJSON DotNetTime | |
ToJSON ZonedTime | |
ToJSON IntSet | |
ToJSON UTCTime | |
ToJSON [Char] | |
ToJSON a => ToJSON [a] | |
ToJSON (Ratio Integer) | |
ToJSON a => ToJSON (Maybe a) | |
ToJSON a => ToJSON (First a) | |
ToJSON a => ToJSON (Last a) | |
ToJSON a => ToJSON (Dual a) | |
ToJSON a => ToJSON (HashSet a) | |
ToJSON a => ToJSON (Vector a) | |
(Vector Vector a, ToJSON a) => ToJSON (Vector a) | |
(Storable a, ToJSON a) => ToJSON (Vector a) | |
(Prim a, ToJSON a) => ToJSON (Vector a) | |
ToJSON a => ToJSON (IntMap a) | |
ToJSON a => ToJSON (Set a) | |
HasResolution a => ToJSON (Fixed a) | |
(ToJSON a, ToJSON b) => ToJSON (Either a b) | |
(ToJSON a, ToJSON b) => ToJSON (a, b) | |
ToJSON v => ToJSON (HashMap String v) | |
ToJSON v => ToJSON (HashMap ByteString v) | |
ToJSON v => ToJSON (HashMap ByteString v) | |
ToJSON v => ToJSON (HashMap Text v) | |
ToJSON v => ToJSON (HashMap Text v) | |
ToJSON v => ToJSON (Map String v) | |
ToJSON v => ToJSON (Map ByteString v) | |
ToJSON v => ToJSON (Map ByteString v) | |
ToJSON v => ToJSON (Map Text v) | |
ToJSON v => ToJSON (Map Text v) | |
(ToJSON a, ToJSON b, ToJSON c) => ToJSON (a, b, c) | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON (a, b, c, d) |
class FromJSON a where
Instances
Encoding/decoding
encodeFile :: ToJSON a => FilePath -> a -> IO ()
decodeFile :: FromJSON a => FilePath -> IO (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))