Skip to content

Instantly share code, notes, and snippets.

@propensive
Created November 26, 2012 14:53
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save propensive/4148607 to your computer and use it in GitHub Desktop.
Save propensive/4148607 to your computer and use it in GitHub Desktop.
Rapture I/O JSON extraction example
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