from
Converts the given value to a JsonValue.
This method works best on primitive types, List values, Map values, and nested combinations of these. For example:
// Create primitive JSON values
val nullValue: JsonValue = JsonValue.from(null)
val booleanValue: JsonValue = JsonValue.from(true)
val numberValue: JsonValue = JsonValue.from(42)
val stringValue: JsonValue = JsonValue.from("Hello World!")
// Create a JSON array value equivalent to `["Hello", "World"]`
val arrayValue: JsonValue = JsonValue.from(listOf("Hello", "World"))
// Create a JSON object value equivalent to `{ "a": 1, "b": 2 }`
val objectValue: JsonValue = JsonValue.from(mapOf(
"a" to 1,
"b" to 2,
))
// Create an arbitrarily nested JSON equivalent to:
// {
// "a": [1, 2],
// "b": [3, 4]
// }
val complexValue: JsonValue = JsonValue.from(mapOf(
"a" to listOf(1, 2),
"b" to listOf(3, 4),
))Content copied to clipboard
Throws
if value is not JSON serializable.