| // This file was automatically generated from json.md by Knit tool. Do not edit. | |
| package example.exampleJson16 | |
| import kotlinx.serialization.* | |
| import kotlinx.serialization.json.* | |
| fun main() { | |
| val element = Json.parseToJsonElement(""" | |
| { | |
| "name": "kotlinx.serialization", | |
| "forks": [{"votes": 42}, {"votes": 9000}, {}] | |
| } | |
| """) | |
| val sum = element | |
| .jsonObject["forks"]!! | |
| .jsonArray.sumOf { it.jsonObject["votes"]?.jsonPrimitive?.int ?: 0 } | |
| println(sum) | |
| } |