Implicits
Provides extension methods and implicit conversions.
Givens
Givens
Converts Right to JsonValue using right converter or converts Left
using left.
Converts Right to JsonValue using right converter or converts Left
using left.
Converts Iterable to JsonArray.
Converts Iterable to JsonArray.
Converts JsonValue to collection of converted values.
Converts JsonValue to collection of converted values.
Converts JsonValue to Right using right converter or to Left using
left if right is unsuccessful.
Converts JsonValue to Right using right converter or to Left using
left if right is unsuccessful.
Returns JsonValue as is.
Returns JsonValue as is.
This instance is required to perform actions such as the following:
import little.json.{ Json, JsonValue }
import little.json.Implicits.given
import scala.language.implicitConversions
val json = Json.obj("values" -> Json.arr("abc", 123, true))
// Requires jsonValueToJsonValue
val list = json("values").as[List[JsonValue]]
Converts JsonValue to Some or returns None if value is JsonNull.
Converts JsonValue to Some or returns None if value is JsonNull.
Converts JsonValue to Success or returns Failure if unsuccessful.
Converts JsonValue to Success or returns Failure if unsuccessful.
Converts Some to JsonValue or returns JsonNull if None.
Converts Some to JsonValue or returns JsonNull if None.
Converts Success to JsonValue or returns JsonNull if Failure.
Converts Success to JsonValue or returns JsonNull if Failure.
Converts (String, T) to (String, JsonValue).
Converts (String, T) to (String, JsonValue).
Extensions
Extensions
Gets value in JSON object.
Gets value in JSON object.
- Value Params
- name
field name
- Throws
- ClassCastException
if not JsonObject
Gets value in JSON array.
Gets value in JSON array.
- Value Params
- index
array index
- Throws
- ClassCastException
if not JsonArray
Collects values with given field name while traversing nested objects and arrays.
Collects values with given field name while traversing nested objects and arrays.
import little.json.Json
import little.json.Implicits.{ *, given }
val json = Json.parse("""{
"node": {
"name": "localhost",
"users": [
{ "id": 0, "name": "root" },
{ "id": 1000, "name": "jza" }
]
}
}""")
val names = (json \\ "name").map(_.as[String])
assert { names == Seq("localhost", "root", "jza") }
- Value Params
- name
field name