@@ -114,24 +114,31 @@ verbJsonType :: forall a b. b -> (a -> b) -> (b -> (a -> b) -> Json -> b) -> Jso
114
114
verbJsonType def f g = g def f
115
115
116
116
-- Tests
117
+
117
118
isJsonType :: forall a . (Boolean -> (a -> Boolean ) -> Json -> Boolean ) -> Json -> Boolean
118
119
isJsonType = verbJsonType false (const true )
119
120
121
+ -- | Check if the provided `Json` is the `null` value
120
122
isNull :: Json -> Boolean
121
123
isNull = isJsonType caseJsonNull
122
124
125
+ -- | Check if the provided `Json` is a `Boolean`
123
126
isBoolean :: Json -> Boolean
124
127
isBoolean = isJsonType caseJsonBoolean
125
128
129
+ -- | Check if the provided `Json` is a `Number`
126
130
isNumber :: Json -> Boolean
127
131
isNumber = isJsonType caseJsonNumber
128
132
133
+ -- | Check if the provided `Json` is a `String`
129
134
isString :: Json -> Boolean
130
135
isString = isJsonType caseJsonString
131
136
137
+ -- | Check if the provided `Json` is an `Array`
132
138
isArray :: Json -> Boolean
133
139
isArray = isJsonType caseJsonArray
134
140
141
+ -- | Check if the provided `Json` is an `Object`
135
142
isObject :: Json -> Boolean
136
143
isObject = isJsonType caseJsonObject
137
144
@@ -144,60 +151,88 @@ toJsonType
144
151
-> Maybe a
145
152
toJsonType = verbJsonType Nothing Just
146
153
154
+ -- | Convert `Json` to the `Unit` value if the `Json` is the null value
147
155
toNull :: Json -> Maybe Unit
148
156
toNull = toJsonType caseJsonNull
149
157
158
+ -- | Convert `Json` to a `Boolean` value, if the `Json` is a boolean.
150
159
toBoolean :: Json -> Maybe Boolean
151
160
toBoolean = toJsonType caseJsonBoolean
152
161
162
+ -- | Convert `Json` to a `Number` value, if the `Json` is a number.
153
163
toNumber :: Json -> Maybe Number
154
164
toNumber = toJsonType caseJsonNumber
155
165
166
+ -- | Convert `Json` to a `String` value, if the `Json` is a string. To write a
167
+ -- | `Json` value to a JSON string, see `stringify`.
156
168
toString :: Json -> Maybe String
157
169
toString = toJsonType caseJsonString
158
170
171
+ -- | Convert `Json` to an `Array` of `Json` values, if the `Json` is an array.
159
172
toArray :: Json -> Maybe (Array Json )
160
173
toArray = toJsonType caseJsonArray
161
174
175
+ -- | Convert `Json` to an `Object` of `Json` values, if the `Json` is an object.
162
176
toObject :: Json -> Maybe (Object Json )
163
177
toObject = toJsonType caseJsonObject
164
178
165
179
-- Encoding
166
180
181
+ -- | Construct `Json` from a `Boolean` value
167
182
foreign import fromBoolean :: Boolean -> Json
183
+
184
+ -- | Construct `Json` from a `Number` value
168
185
foreign import fromNumber :: Number -> Json
186
+
187
+ -- | Construct `Json` from a `String` value. If you would like to parse a string
188
+ -- | of JSON into valid `Json`, see `jsonParser`.
169
189
foreign import fromString :: String -> Json
190
+
191
+ -- | Construct `Json` from an array of `Json` values
170
192
foreign import fromArray :: Array Json -> Json
193
+
194
+ -- | Construct `Json` from an object with `Json` values
171
195
foreign import fromObject :: Object Json -> Json
172
196
173
197
-- Defaults
174
198
199
+ -- | The JSON null value represented as `Json`
175
200
foreign import jsonNull :: Json
176
201
202
+ -- | The true boolean value represented as `Json`
177
203
jsonTrue :: Json
178
204
jsonTrue = fromBoolean true
179
205
206
+ -- | The false boolean value represented as `Json`
180
207
jsonFalse :: Json
181
208
jsonFalse = fromBoolean false
182
209
210
+ -- | The number zero represented as `Json`
183
211
jsonZero :: Json
184
212
jsonZero = fromNumber 0.0
185
213
214
+ -- | An empty string represented as `Json`
186
215
jsonEmptyString :: Json
187
216
jsonEmptyString = fromString " "
188
217
218
+ -- | An empty array represented as `Json`
189
219
jsonEmptyArray :: Json
190
220
jsonEmptyArray = fromArray []
191
221
222
+ -- | An empty object represented as `Json`
192
223
jsonEmptyObject :: Json
193
224
jsonEmptyObject = fromObject Obj .empty
194
225
226
+ -- | Constructs a `Json` array value containing only the provided value
195
227
jsonSingletonArray :: Json -> Json
196
228
jsonSingletonArray j = fromArray [j]
197
229
230
+ -- | Constructs a `Json` object value containing only the provided key and value
198
231
jsonSingletonObject :: String -> Json -> Json
199
232
jsonSingletonObject key val = fromObject (Obj .singleton key val)
200
233
234
+ -- | Converts a `Json` value to a JSON string. To retrieve a string from a `Json`
235
+ -- | string value, see `fromString`.
201
236
foreign import stringify :: Json -> String
202
237
203
238
foreign import _caseJson
0 commit comments