1 // This file was automatically generated from json.md by Knit tool. Do not edit. 2 package example.exampleJson16 3 4 import kotlinx.serialization.* 5 import kotlinx.serialization.json.* 6 mainnull7fun main() { 8 val element = Json.parseToJsonElement(""" 9 { 10 "name": "kotlinx.serialization", 11 "forks": [{"votes": 42}, {"votes": 9000}, {}] 12 } 13 """) 14 val sum = element 15 .jsonObject["forks"]!! 16 .jsonArray.sumOf { it.jsonObject["votes"]?.jsonPrimitive?.int ?: 0 } 17 println(sum) 18 } 19