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:
Here is the JsonElement
definition:
Ending
I wish you the best of luck in this and future challenges and can't wait to see your solutions :)
Marcin Moskala is a highly experienced developer and Kotlin instructor as the founder of Kt. Academy, an official JetBrains partner specializing in Kotlin training, is known for his significant contributions to the Kotlin community. Moskala is the author of several widely recognized books, including "Effective Kotlin," "Kotlin Coroutines," "Functional Kotlin," "Advanced Kotlin," "Kotlin Essentials," and "Android Development with Kotlin."
Beyond his literary achievements, Moskala is the author of the largest Medium publication dedicated to Kotlin. As a respected speaker, he has been invited to share his insights at numerous programming conferences, including events such as Droidcon and the prestigious Kotlin Conf, the premier conference dedicated to the Kotlin programming language.