score:10
Accepted answer
You need to give a hint to the Scala compiler so that it is able to select the right method:
val eventType = JsonPath.read[String](jsonString, "$.message_metadata.event_type")
Here is the complete test app:
import com.jayway.jsonpath.JsonPath
object TestApp extends App {
val jsonString =
"""{
| "message_payload":"6b700b000006",
| "message_encryption_version":"2.0",
| "message_version":"1.0",
| "message_metadata":{
| "marketplace_id":"1",
| "workflow_id":"5906bd4e-52eb-4e2d-9a16-034fb67572f1",
| "hostname":"dev-dsk-shivabo-2b-3c0a1bd6.us-west-2.amazon.com",
| "event_type":"MerchantRegistrationFraudEvaluation",
| "event_date":"1513665186657"
| }
|}""".stripMargin
val eventType = JsonPath.read[String](jsonString, "$.message_metadata.event_type")
println(eventType) // MerchantRegistrationFraudEvaluation
}
Source: stackoverflow.com
Related Query
- Get a specific parameter from a json string using JsonPath in scala
- Extracting string from JSON using Json4s using Scala
- Get Long from a string using Scala
- Extracting a field from a Json string using jackson mapper in Scala
- How can i create a dataframe from a complex JSON in string format using Spark scala
- Extract a specific JSON structure from a json string in a Spark Rdd - Scala
- Reading value from JSON string Scala using ScalaJson
- How to read list of string from JSON file using Scala
- How to get list of json strings from sinlgle line multi json string in scala
- How do I get JSON string from Mongo db using Play (and Salat)?
- Scala - Get last two characters from string
- get min and max from a specific column scala spark dataframe
- Serializing a scala object into a JSon String using lift-json
- scala - get class from a string
- Get form parameter value from request in Play 2.0 Scala controller
- Print json string in one line using circe in scala
- How to read json data using scala from kafka topic in apache spark
- How can I deserialize from JSON with Scala using *non-case* classes?
- Re-using A Schema from JSON within a Spark DataFrame using Scala
- How to get max length of string column from dataframe using scala?
- Parsing a Json String in Scala using Play framework
- Why do I get "$outer" In my json string when using lift-json?
- How to get all sub-strings of a specific format from a string
- Scala Object - get reference from string (in Scala 2.10)
- Get value from Option parameter in scala
- Get Boolean Value from VM Parameter in Scala
- Using forall() in extracting String from Option[String] in scala
- How to get String value from Rep[String] using slick 3 in Play scala?
- extracting keys from json string using json4s
- Flatten any nested json string and convert to dataframe using spark scala
More Query from same tag
- Stuck creating implicitly convertable from/to Int Natgural numbers class
- Scala Actors in Scala 2.10 don't get recognized
- Play Framework: How to define a writable object in scala?
- Scala XML Extracting
- Play framework Twirl template comparing javascript element and scala variable
- Scala: explicitly specifying context bound in a second constructor
- Designing a filter using scala - For loop unrolling
- How to parse a file with newline character, escaped with \ and not quoted
- Variable Setter Type Error: Overloaded method needs result type
- dependency injection vs partial application in Scala
- How to connect SQL Server from play 2.4.6
- java.lang.NoSuchMethodError: scala.reflect.api.JavaUniverse.runtimeMirror
- Know specified fields on serverside in GraphQL / Sangria-Graphql
- How to write and read delta format with Zeppelin?(Delta Lake installed and imported)
- Column bind two RDD in scala spark without KEYs
- way to connect windows on intellij to spark on cluster
- Adding elements to a list in a for loop
- Render React UI in play framework
- akka stream integrating akka-htpp web request call into stream
- Scala Grpc failed with error io.grpc.StatusRuntimeException: CANCELLED: Failed to read message
- java.lang.IllegalArgumentException: Field "label" does not exist using SparkML
- Is it possible to flatten this particular sequence in scala?
- Parse JSON with Interface/trait and Different implementations
- Scala - Apply a function to each value in a dataframe column
- Writing Builder pattern in Scala while hiding case class direct access
- value id is not a member of securesocial.core.Identity
- Bash script to insert code from one file at a specific location in another file?
- How to do window function inside a when?
- Custom row (List of CustomTypes) to spark dataframe
- How to get the sum of adding two Pairs in scala?