Last active
November 4, 2020 01:57
-
-
Save rupeshtr78/15e957a8ec8bac16fcf8080b64b29fa1 to your computer and use it in GitHub Desktop.
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
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