Last active
September 2, 2016 08:42
-
-
Save andrearota/8093b2ed83e8a51356b67344ba87e510 to your computer and use it in GitHub Desktop.
Using Lift Json libraries to parse Json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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