Converts the given [value] to a [JsonValue].
public JsonValue from(Any value)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
JsonValue nullValue = JsonValue.from(null);
JsonValue booleanValue = JsonValue.from(true);
JsonValue numberValue = JsonValue.from(42);
JsonValue stringValue = JsonValue.from("Hello World!");
// Create a JSON array value equivalent to `["Hello", "World"]`
JsonValue arrayValue = JsonValue.from(List.of("Hello", "World"));
// Create a JSON object value equivalent to `{ "a": 1, "b": 2 }`
JsonValue objectValue = JsonValue.from(Map.of(
"a", 1,
"b", 2
));
// Create an arbitrarily nested JSON equivalent to:
// {
// "a": [1, 2],
// "b": [3, 4]
// }
JsonValue complexValue = JsonValue.from(Map.of(
"a", List.of(1, 2),
"b", List.of(3, 4)
));
IllegalArgumentException: if [value] is not JSON serializable.| Name | Type | Description |
|---|---|---|
value* | Any? |