How do I get a particular field out of a Json object in Scala? I feel like I'm going in circles.
import org.json4s._
import org.json4s.jackson.JsonMethods._
val me = parse(""" {"name":"brian", "state":"frustrated"} """)
Now I want just the state. I was looking for something like
me("state") -> "frustrated"
I have tried
me("state")
me.get("state")
me \ "state" <thanks for the idea>
me['state']
me.state
me.NOOOOOOOOOO!!!!!!!
Help?
I think your code has errta, and below may be right code.
Assume type of value in state field is fixed, say its type is string.
val me = parse("""{"name":"brian", "state":"frustrated"}""")
val JString(state) = me \ "state"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With