on 1.4.1.0 help sign in
141 lines 2.9 kB history raw
1{-# LANGUAGE NoImplicitPrelude #-}
2-- |
3-- Module: Data.Aeson.Types
4-- Copyright: (c) 2011-2016 Bryan O'Sullivan
5-- (c) 2011 MailRank, Inc.
6-- License: BSD3
7-- Maintainer: Bryan O'Sullivan <bos@serpentine.com>
8-- Stability: experimental
9-- Portability: portable
10--
11-- Types for working with JSON data.
13module Data.Aeson.Types
14 (
15 -- * Core JSON types
16 Value(..)
17 , Encoding
18 , unsafeToEncoding
19 , fromEncoding
20 , Series
21 , Array
22 , emptyArray
23 , Pair
24 , Object
25 , emptyObject
26 -- * Convenience types and functions
27 , DotNetTime(..)
28 , typeMismatch
29 -- * Type conversion
30 , Parser
31 , Result(..)
32 , FromJSON(..)
33 , fromJSON
34 , parse
35 , parseEither
36 , parseMaybe
37 , ToJSON(..)
38 , KeyValue(..)
39 , modifyFailure
40 , parserThrowError
41 , parserCatchError
43 -- ** Keys for maps
44 , ToJSONKey(..)
45 , ToJSONKeyFunction(..)
46 , toJSONKeyText
47 , contramapToJSONKeyFunction
48 , FromJSONKey(..)
49 , FromJSONKeyFunction(..)
50 , fromJSONKeyCoerce
51 , coerceFromJSONKeyFunction
52 , mapFromJSONKeyFunction
54 -- ** Liftings to unary and binary type constructors
55 , FromJSON1(..)
56 , parseJSON1
57 , FromJSON2(..)
58 , parseJSON2
59 , ToJSON1(..)
60 , toJSON1
61 , toEncoding1
62 , ToJSON2(..)
63 , toJSON2
64 , toEncoding2
66 -- ** Generic JSON classes
67 , GFromJSON(..)
68 , FromArgs(..)
69 , GToJSON
70 , GToEncoding
71 , ToArgs(..)
72 , Zero
73 , One
74 , genericToJSON
75 , genericLiftToJSON
76 , genericToEncoding
77 , genericLiftToEncoding
78 , genericParseJSON
79 , genericLiftParseJSON
81 -- * Inspecting @'Value's@
82 , withObject
83 , withText
84 , withArray
85 , withScientific
86 , withBool
87 , withEmbeddedJSON
89 , pairs
90 , foldable
91 , (.:)
92 , (.:?)
93 , (.:!)
94 , (.!=)
95 , object
96 , parseField
97 , parseFieldMaybe
98 , parseFieldMaybe'
99 , explicitParseField
100 , explicitParseFieldMaybe
101 , explicitParseFieldMaybe'
103 , listEncoding
104 , listValue
105 , listParser
107 -- * Generic and TH encoding configuration
108 , Options
110 -- ** Options fields
111 -- $optionsFields
112 , fieldLabelModifier
113 , constructorTagModifier
114 , allNullaryToStringTag
115 , omitNothingFields
116 , sumEncoding
117 , unwrapUnaryRecords
118 , tagSingleConstructors
120 -- ** Options utilities
121 , SumEncoding(..)
122 , camelTo
123 , camelTo2
124 , defaultOptions
125 , defaultTaggedObject
126 ) where
128import Prelude.Compat
130import Data.Aeson.Encoding (Encoding, unsafeToEncoding, fromEncoding, Series, pairs)
131import Data.Aeson.Types.Class
132import Data.Aeson.Types.Internal
133import Data.Foldable (toList)
135-- | Encode a 'Foldable' as a JSON array.
136foldable :: (Foldable t, ToJSON a) => t a -> Encoding
137foldable = toEncoding . toList
138{-# INLINE foldable #-}
140-- $optionsFields
141-- The functions here are in fact record fields of the 'Options' type.