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 , GToJSON' 81 , ToArgs 82 , Zero 83 , One 84 , genericToJSON 85 , genericLiftToJSON 86 , genericToEncoding 87 , genericLiftToEncoding 88 , genericParseJSON 89 , genericLiftParseJSON 90 91 -- * Inspecting @'Value's@ 92 , withObject 93 , withText 94 , withArray 95 , withScientific 96 , withBool 97 , withEmbeddedJSON 98 99 , pairs 100 , foldable 101 , (.:) 102 , (.:?) 103 , (.:!) 104 , (.!=) 105 , object 106 , parseField 107 , parseFieldMaybe 108 , parseFieldMaybe' 109 , explicitParseField 110 , explicitParseFieldMaybe 111 , explicitParseFieldMaybe' 112 113 , listEncoding 114 , listValue 115 , listParser 116 117 -- * Generic and TH encoding configuration 118 , Options 119 120 -- ** Options fields 121 -- $optionsFields 122 , fieldLabelModifier 123 , constructorTagModifier 124 , allNullaryToStringTag 125 , omitNothingFields 126 , sumEncoding 127 , unwrapUnaryRecords 128 , tagSingleConstructors 129 , rejectUnknownFields 130 131 -- ** Options utilities 132 , SumEncoding(..) 133 , camelTo 134 , camelTo2 135 , defaultOptions 136 , defaultTaggedObject 137 138 -- ** Options for object keys 139 , JSONKeyOptions 140 , keyModifier 141 , defaultJSONKeyOptions 142 143 -- * Parsing context 144 , (<?>) 145 , JSONPath 146 , JSONPathElement(..) 147 , formatPath 148 , formatRelativePath 149 ) where 150 151import Prelude.Compat 152 153import Data.Aeson.Encoding (Encoding, unsafeToEncoding, fromEncoding, Series, pairs) 154import Data.Aeson.Types.Class 155import Data.Aeson.Types.Internal 156import Data.Foldable (toList) 157 158-- | Encode a 'Foldable' as a JSON array. 159foldable :: (Foldable t, ToJSON a) => t a -> Encoding 160foldable = toEncoding . toList 161{-# INLINE foldable #-} 162 163-- $optionsFields 164-- The functions here are in fact record fields of the 'Options' type. 165