Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Rapture I/O JSON extraction example

View json.scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
import rapture.io._
 
// Let's parse some JSON
val src: Json = Json.parse("""
{
"foo": "Hello world",
"bar": {
"baz": 42
}
}
""")
 
// This is the same as the JSON string literal:
val src: Json = json"""
{
"foo": "Hello world",
"bar": {
"baz": 42
}
}
"""
 
// We can now access the value bar.baz
val x: Json = src.bar.baz
 
// And get it as an integer
val y: Int = x.get[Int]
 
// Alternatively, we can use an extractor to get the values we want:
val json""" { "bar": { "baz": $x }, "foo": $z }""" = src
 
// Now x = 42 and z = "Hello world".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.