Open
Description
What is your use-case and why do you need this feature?
Maps provide emptyMap()
and mapOf()
helper functions for constructing maps. Lists provide emptyList()
and listOf()
helper functrions for constructing lists.
The element builders buildJsonObject
and buildJsonArray
are useful for more complex object/array construction, but the Of
helpers are better and more readable for simple use cases such as constructing a Language Server Protocol Position object.
Example: Construct an LSP Position object:
val position = jsonObjectOf(
"line" to JsonPrimitive(1),
"character" to JsonPrimitive(8)
)
Example: Construct an LSP PositionEncodingKind array:
val positionEncodings = jsonArrayOf(JsonPrimitive("utf-32"), JsonPrimitive("utf-16"))
Describe the solution you'd like
It would be helpful if there were equivalents for JSON objects and arrays:
emptyJsonObject
-- Construct an empty JSON object.jsonObjectOf
-- Construct a JSON object from a variadic argument array of (key, JSON element value) pairs.emptyJsonArray
-- Constuct an empty JSON array.jsonArrayOf
-- Construct a JSON array from a variadic argument array of JSON element values.