@@ -14,6 +14,33 @@ private enum class State {
14
14
ARRAY ,
15
15
}
16
16
17
+ /* *
18
+ * Parses JSON tokens from a [JSONLexer] into a Kotlin Object.
19
+ * The JSON will be parsed according to:
20
+ * [RFC 8259 - The JavaScript Object Notation (JSON) Data Interchange Format](https://www.rfc-editor.org/rfc/rfc8259).
21
+ *
22
+ * ## Resulting value
23
+ * The resulting value can be (depending on the JSON input) recursively:
24
+ * - Boolean
25
+ * - Null
26
+ * - Number (as a [BigDecimal])
27
+ * - String
28
+ * - Array (as an [ArrayList] with [Any])
29
+ * - Object (as a [HashMap] with [String] to [Any])
30
+ *
31
+ * This value is a single object and can be used however wanted without any other abstractions.
32
+ *
33
+ * ## Error handling
34
+ * If an error happens at the parsing stage, a [JSONParserException] is being thrown.
35
+ *
36
+ * If the lexer is experiencing an error the [JSONLexerException] will be thrown by the lexer
37
+ * and with that this function as well.
38
+ *
39
+ * Both exception types are based upon the [JSONParseException] and with that can both be caught at the same time.
40
+ *
41
+ * @param lexer The lexer which is being used for the tokens
42
+ * @return The resulting JSON value
43
+ */
17
44
@Throws(JSONParseException ::class )
18
45
fun jsonParse (lexer : JSONLexer ): Any? {
19
46
var state = State .START ;
@@ -211,6 +238,36 @@ fun jsonParse(lexer: JSONLexer): Any? {
211
238
return result
212
239
}
213
240
241
+ /* *
242
+ * Parses a JSON string into a Kotlin Object.
243
+ * The JSON will be parsed according to:
244
+ * [RFC 8259 - The JavaScript Object Notation (JSON) Data Interchange Format](https://www.rfc-editor.org/rfc/rfc8259).
245
+ *
246
+ * This function is an abstraction of the [jsonParse] function and uses a [StringJSONLexer] which is initialized with
247
+ * the `input` string and passed to the actual function.
248
+ *
249
+ * ## Resulting value
250
+ * The resulting value can be (depending on the JSON input) recursively:
251
+ * - Boolean
252
+ * - Null
253
+ * - Number (as a [BigDecimal])
254
+ * - String
255
+ * - Array (as an [ArrayList] with [Any])
256
+ * - Object (as a [HashMap] with [String] to [Any])
257
+ *
258
+ * This value is a single object and can be used however wanted without any other abstractions.
259
+ *
260
+ * ## Error handling
261
+ * If an error happens at the parsing stage, a [JSONParserException] is being thrown.
262
+ *
263
+ * If the lexer is experiencing an error the [JSONLexerException] will be thrown by the lexer
264
+ * and with that this function as well.
265
+ *
266
+ * Both exception types are based upon the [JSONParseException] and with that can both be caught at the same time.
267
+ *
268
+ * @param input The input string which is being parsed
269
+ * @return The resulting JSON value
270
+ */
214
271
@Throws(JSONParseException ::class )
215
272
fun jsonParse (input : String ): Any? {
216
273
return jsonParse(StringJSONLexer (input))
0 commit comments