Skip to content

Instantly share code, notes, and snippets.

@andrearota
Last active September 2, 2016 08:42
Show Gist options
  • Save andrearota/8093b2ed83e8a51356b67344ba87e510 to your computer and use it in GitHub Desktop.
Save andrearota/8093b2ed83e8a51356b67344ba87e510 to your computer and use it in GitHub Desktop.
Using Lift Json libraries to parse Json
import net.liftweb.json._
case class Entry(name: String, job: String, scores: Array[Double], weights: Array[Double])
object ParsingJson {
def main(args: Array[String]) = {
implicit val formats = DefaultFormats
val dataset = """
[{
"name": "Foo",
"job": "FooJob",
"scores": [1.0, 2.0],
"weights": [0.1, 0.9]
}, {
"name": "Bar",
"job": "BarJob",
"scores": [3.0, 4.0],
"weights": [0.5, 0.5]
}]
"""
val json = parse(dataset)
val parsed = json.extract[Array[Entry]]
// Print the imported data
for(x <- parsed) {
println(x.name)
println(x.job)
println(x.scores.mkString(", "))
println(x.weights.mkString(", "))
println
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment