blob: f522b3facfb1cb559d60ad9f450d6ed5d88e5fbd [file] [log] [blame]
Leonid Startsevfa569a82021-08-17 22:47:24 +03001// This file was automatically generated from json.md by Knit tool. Do not edit.
2package example.exampleJson20
3
4import kotlinx.serialization.*
5import kotlinx.serialization.json.*
6
Clara Fok93e18122024-04-23 10:28:10 -07007import java.math.BigDecimal
Leonid Startsevfa569a82021-08-17 22:47:24 +03008
Clara Fok93e18122024-04-23 10:28:10 -07009val format = Json { prettyPrint = true }
Leonid Startsev3ac9b892022-01-26 12:45:00 +030010
Leonid Startsevfa569a82021-08-17 22:47:24 +030011fun main() {
Clara Fok93e18122024-04-23 10:28:10 -070012 val pi = BigDecimal("3.141592653589793238462643383279")
13
14 // use JsonUnquotedLiteral to encode raw JSON content
15 val piJsonLiteral = JsonUnquotedLiteral(pi.toString())
16
17 val piJsonDouble = JsonPrimitive(pi.toDouble())
18 val piJsonString = JsonPrimitive(pi.toString())
19
20 val piObject = buildJsonObject {
21 put("pi_literal", piJsonLiteral)
22 put("pi_double", piJsonDouble)
23 put("pi_string", piJsonString)
24 }
25
26 println(format.encodeToString(piObject))
Leonid Startsevfa569a82021-08-17 22:47:24 +030027}