Advent of Kotlin: Week 4

We've started this advent with JSON stringify. This week, we will do the opposite: JSON parsing.

The process of parsing is transforming a string with an object representing an objects in JSON format into a representation of this object. Here is an example:

assertEquals( JsonObject( "o" to JsonObject( "a" to JsonString("AAA"), "b" to JsonNumber(123.45), "c" to JsonBoolean(true), "d" to JsonBoolean(false), "e" to JsonNull, ) ), parseJson("""{"o":{"a":"AAA","b":123.45,"c":true,"d":false,"e":null}}""") )

In this exercise, you might find regex really useful. If you don't know it, this course might be useful.

Here you the definition of the JSON parse function:

https://github.com/MarcinMoskala/advent-2021/blob/master/src/main/kotlin/week4/JsonParse.kt

Here is the JsonElement definition:

https://github.com/MarcinMoskala/advent-2021/blob/master/src/main/kotlin/week1/JsonStringify.kt

Here are unit tests:

https://github.com/MarcinMoskala/advent-2021/blob/master/src/test/kotlin/week4/JsonParseTest.kt

Ending

I wish you the best of luck in this and future challenges and can't wait to see your solutions :)