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.
12
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    , unexpected
30    -- * Type conversion
31    , Parser
32    , Result(..)
33    , FromJSON(..)
34    , fromJSON
35    , parse
36    , parseEither
37    , parseMaybe
38    , parseFail
39    , ToJSON(..)
40    , KeyValue(..)
41    , modifyFailure
42    , prependFailure
43    , parserThrowError
44    , parserCatchError
45
46    -- ** Keys for maps
47    , ToJSONKey(..)
48    , ToJSONKeyFunction(..)
49    , toJSONKeyText
50    , contramapToJSONKeyFunction
51    , FromJSONKey(..)
52    , FromJSONKeyFunction(..)
53    , fromJSONKeyCoerce
54    , coerceFromJSONKeyFunction
55    , mapFromJSONKeyFunction
56
57    -- *** Generic keys
58    , GToJSONKey()
59    , genericToJSONKey
60    , GFromJSONKey()
61    , genericFromJSONKey
62
63    -- ** Liftings to unary and binary type constructors
64    , FromJSON1(..)
65    , parseJSON1
66    , FromJSON2(..)
67    , parseJSON2
68    , ToJSON1(..)
69    , toJSON1
70    , toEncoding1
71    , ToJSON2(..)
72    , toJSON2
73    , toEncoding2
74
75    -- ** Generic JSON classes
76    , GFromJSON(..)
77    , FromArgs(..)
78    , GToJSON
79    , GToEncoding
80    , ToArgs(..)
81    , Zero
82    , One
83    , genericToJSON
84    , genericLiftToJSON
85    , genericToEncoding
86    , genericLiftToEncoding
87    , genericParseJSON
88    , genericLiftParseJSON
89
90    -- * Inspecting @'Value's@
91    , withObject
92    , withText
93    , withArray
94    , withScientific
95    , withBool
96    , withEmbeddedJSON
97
98    , pairs
99    , foldable
100    , (.:)
101    , (.:?)
102    , (.:!)
103    , (.!=)
104    , object
105    , parseField
106    , parseFieldMaybe
107    , parseFieldMaybe'
108    , explicitParseField
109    , explicitParseFieldMaybe
110    , explicitParseFieldMaybe'
111
112    , listEncoding
113    , listValue
114    , listParser
115
116    -- * Generic and TH encoding configuration
117    , Options
118
119    -- ** Options fields
120    -- $optionsFields
121    , fieldLabelModifier
122    , constructorTagModifier
123    , allNullaryToStringTag
124    , omitNothingFields
125    , sumEncoding
126    , unwrapUnaryRecords
127    , tagSingleConstructors
128    , rejectUnknownFields
129
130    -- ** Options utilities
131    , SumEncoding(..)
132    , camelTo
133    , camelTo2
134    , defaultOptions
135    , defaultTaggedObject
136
137    -- ** Options for object keys
138    , JSONKeyOptions
139    , keyModifier
140    , defaultJSONKeyOptions
141
142    -- * Parsing context
143    , (<?>)
144    , JSONPath
145    , JSONPathElement(..)
146    , formatPath
147    , formatRelativePath
148    ) where
149
150import Prelude.Compat
151
152import Data.Aeson.Encoding (Encoding, unsafeToEncoding, fromEncoding, Series, pairs)
153import Data.Aeson.Types.Class
154import Data.Aeson.Types.Internal
155import Data.Foldable (toList)
156
157-- | Encode a 'Foldable' as a JSON array.
158foldable :: (Foldable t, ToJSON a) => t a -> Encoding
159foldable = toEncoding . toList
160{-# INLINE foldable #-}
161
162-- $optionsFields
163-- The functions here are in fact record fields of the 'Options' type.
164