I was looking for some lib have Kotlin DSL to buil...
# javascript
f
I was looking for some lib have Kotlin DSL to build JSON like Koson for javascript.
f
@turansky thx, I tried but is very verbose. I was looking for a simpler way but I see that it doesn't exist.
t
What means "simpler way"?
Possibly you need #serialization
a
@frank
json
function from
kotlin.js
is almost similar to koson. How verbose is this?
Copy code
val obj2 = json(
  "one" to 1,
  "three" to 3,
  "map" to json(
              
  ))
3
f
@andylamax thx, I was looking for this. I was using
Pair
inside of
json ()
and it very verbose:
Copy code
json(Pair("msg",item.textContent), Pair("type",type))
a
extra syntax
Copy code
json(
            "numbers" to json(
                "integers" to arrayOf(1, 2, 3, 4, 5, 6, 7, 8),
                "naturals" to arrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
            ),
            "characters" to arrayOf('A', 'B', 'C', 'D'),
            "users" to arrayOf(
                json(
                    "name" to "John Wick",
                    "weapon" to "book"
                ),
                json(
                    "name" to "Thanos",
                    "weapon" to "Infinity Stones"
                )
            )
        )
f
@andylamax, if need jsonArray like this:
Copy code
[ 
{msg: "msg" }, 
{msg: "msg" } 
]
I have to define
Array<Json>
variable or there is some function or object that returns jsonArray?
a
Copy code
arrayOf(
    json("msg" to "msg"),
    json("msg" to "msg")
)
f
arrayOf(
json("msg" to "msg"),
json("msg" to "msg")
)
Yes, I have seen that I am wrong and they are 2 json objects in array.
a
That is the syntax, anyway