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 Text | |
ToJSON Text | |
ToJSON ByteString | |
ToJSON ByteString | |
ToJSON Value | |
ToJSON DotNetTime | |
ToJSON Number | |
ToJSON ZonedTime | |
ToJSON IntSet | |
ToJSON UTCTime | |
ToJSON [Char] | |
ToJSON a => ToJSON [a] | |
ToJSON (Ratio Integer) | |
ToJSON a => ToJSON (Maybe a) | |
ToJSON a => ToJSON (Dual a) | |
ToJSON a => ToJSON (IntMap a) | |
ToJSON a => ToJSON (Vector a) | |
ToJSON a => ToJSON (HashSet a) | |
(Storable a, ToJSON a) => ToJSON (Vector a) | |
(Prim a, ToJSON a) => ToJSON (Vector a) | |
(Vector Vector a, ToJSON a) => ToJSON (Vector a) | |
ToJSON a => ToJSON (Set a) | |
ToJSON a => ToJSON (Last a) | |
HasResolution a => ToJSON (Fixed a) | |
ToJSON a => ToJSON (First a) | |
(ToJSON a, ToJSON b) => ToJSON (Either a b) | |
(ToJSON a, ToJSON b) => ToJSON (a, b) | |
ToJSON v => ToJSON (Map String v) | |
ToJSON v => ToJSON (Map Text v) | |
ToJSON v => ToJSON (Map Text v) | |
ToJSON v => ToJSON (Map ByteString v) | |
ToJSON v => ToJSON (Map ByteString v) | |
ToJSON v => ToJSON (HashMap String v) | |
ToJSON v => ToJSON (HashMap Text v) | |
ToJSON v => ToJSON (HashMap Text v) | |
ToJSON v => ToJSON (HashMap ByteString v) | |
ToJSON v => ToJSON (HashMap ByteString 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
FromJSON Bool | |
FromJSON Char | |
FromJSON Double | |
FromJSON Float | |
FromJSON Int | |
FromJSON Int8 | |
FromJSON Int16 | |
FromJSON Int32 | |
FromJSON Int64 | |
FromJSON Integer | |
FromJSON Word | |
FromJSON Word8 | |
FromJSON Word16 | |
FromJSON Word32 | |
FromJSON Word64 | |
FromJSON () | |
FromJSON Text | |
FromJSON Text | |
FromJSON ByteString | |
FromJSON ByteString | |
FromJSON Value | |
FromJSON DotNetTime | |
FromJSON Number | |
FromJSON ZonedTime | |
FromJSON IntSet | |
FromJSON UTCTime | |
FromJSON [Char] | |
FromJSON a => FromJSON [a] | |
FromJSON (Ratio Integer) | |
FromJSON a => FromJSON (Maybe a) | |
FromJSON a => FromJSON (Dual a) | |
FromJSON a => FromJSON (IntMap a) | |
FromJSON a => FromJSON (Vector a) | |
(Eq a, Hashable a, FromJSON a) => FromJSON (HashSet a) | |
(Storable a, FromJSON a) => FromJSON (Vector a) | |
(Prim a, FromJSON a) => FromJSON (Vector a) | |
(Vector Vector a, FromJSON a) => FromJSON (Vector a) | |
(Ord a, FromJSON a) => FromJSON (Set a) | |
FromJSON a => FromJSON (Last a) | |
HasResolution a => FromJSON (Fixed a) | |
FromJSON a => FromJSON (First a) | |
(FromJSON a, FromJSON b) => FromJSON (Either a b) | |
(FromJSON a, FromJSON b) => FromJSON (a, b) | |
FromJSON v => FromJSON (Map String v) | |
FromJSON v => FromJSON (Map Text v) | |
FromJSON v => FromJSON (Map Text v) | |
FromJSON v => FromJSON (Map ByteString v) | |
FromJSON v => FromJSON (Map ByteString v) | |
FromJSON v => FromJSON (HashMap String v) | |
FromJSON v => FromJSON (HashMap Text v) | |
FromJSON v => FromJSON (HashMap Text v) | |
FromJSON v => FromJSON (HashMap ByteString v) | |
FromJSON v => FromJSON (HashMap ByteString v) | |
(FromJSON a, FromJSON b, FromJSON c) => FromJSON (a, b, c) | |
(FromJSON a, FromJSON b, FromJSON c, FromJSON d) => FromJSON (a, b, c, d) |
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))