Skip to content

Instantly share code, notes, and snippets.

@rupeshtr78
Last active November 4, 2020 01:57
Show Gist options
  • Save rupeshtr78/15e957a8ec8bac16fcf8080b64b29fa1 to your computer and use it in GitHub Desktop.
Save rupeshtr78/15e957a8ec8bac16fcf8080b64b29fa1 to your computer and use it in GitHub Desktop.
package scalabeginner.jsonJackson
import org.json4s._
import org.json4s.jackson.JsonMethods._
import scala.io.Source
case class Person(firstName: String, lastName: String, age: Int)
object ReadJson extends App {
implicit val formats= DefaultFormats
val jsonSource = Source.fromFile("data/person.json")
val jsonParse = parse(jsonSource.reader())
jsonSource.close()
val jsonPerson = jsonParse.extract[List[Person]] // implicit format required
println(jsonPerson)
//List(Person(Rupesh,Raghavan,42), Person(Roopa,Rupesh,33))
}
/*
https://www.hackingnote.com/en/scala/json4s
[
{
"firstName": "Rupesh",
"lastName": "Raghavan",
"age": 42
},
{
"firstName": "Roopa",
"lastName": "Rupesh",
"age": 33
}
]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment