Soren Valle
09/06/2019, 12:21 AMclass JsonObject {
val obj = js("({})")
infix fun <T : Any> String.l(other: T) {
obj[this] = other
}
}
fun jo(builder: JsonObject.() -> Unit): Any {
return JsonObject().apply(builder).obj as Any
}
fun main() {
val test = jo {
"this" l "that"
"this other" l 1
"user" l jo {
"first_name" l "jane"
"last_name" l "doe"
}
}
}
jw
09/06/2019, 12:25 AMSoren Valle
09/06/2019, 12:27 AMjw
09/06/2019, 12:29 AMjw
09/06/2019, 12:30 AMval test = json(
"test" to "that",
"this other" to 1,
"user" to json(
"first_name" to "jane",
"last_name" to "doe"
)
)
Soren Valle
09/06/2019, 12:31 AMSebastian Sellmair [JB]
09/06/2019, 7:30 AMjo
something like jsonObject
and the infix l
to something like with
?thana
09/06/2019, 9:36 AMto
turansky
09/08/2019, 3:14 PMfun jso(block: dynamic.() -> Unit): dynamic {
val o = js("({})")
block(o)
return o
}
Example:
val test = jso {
test = "that"
other = 1
user = jso {
first_name = "jane"
last_name = "doe"
}
}
DALDEI
09/10/2019, 2:00 AM