score:23
Accepted answer
Your code is correct except that your JSON is simply an array, hence a List[User]
. There are two ways to fix this, with a slightly different outcome:
Solution 1: Fix your json to
{"users":
[
{"name": "Foo", "emails": ["Foo@gmail.com", "foo2@gmail.com"]},
{"name": "Bar", "emails": ["Bar@gmail.com", "bar@gmail.com"]}
]
}
Solution2: Change the type parameter of extract to
val obj = parse(json).extract[List[User]]
Source: stackoverflow.com
Related Query
- How to parse and extract information from json array using json4s
- How can I select a non-sequential subset elements from an array using Scala and Spark?
- How to read a json response from a akka-http response entity using json4s
- How can I parse a json and extract to different case classes depending of its content
- Generating Json string using Json4S from a list containing Some and None values
- Manipulating array in JSON using Scala and JSON4S
- How to extract binary information from a database using Anorm with Scala
- How to read JSON body from Akka HTTP POST request and send the final response as JSON array
- How to extract extra (key,value) from Json using play-json in scala?
- How to extract my case class from Json using Json4s?
- How to Parse Json String received from HTTP and loop through the values
- How to parse json using json4s so that let primitive values become custom case class?
- Scala: How do I extract the first secound third and fourth byte from an integer using bit operators to binary and back?
- Extract array from list of json strings using Spark
- How to get values from nested json array using spark?
- How to read data from json array and pass it to Gatling on run time in loop
- How to extract table information from a cell in dataframe using Scala in Spark
- how to filter and extract case class objects from big flat csv files using shapeless?
- How to parse multiple lists into array of json objects, using Scala?
- how to read an array of objects from a json config file using scala
- How to select multiple column from database using scala Play2.6 and with proper json response header
- How to parse JSON in Scala using standard Scala classes?
- How can I construct and parse a JSON string in Scala / Lift
- How to download and save a file from the internet using Scala?
- How to read records in JSON format from Kafka using Structured Streaming?
- download a zip from url and extract it in resource using SBT
- How to create a Row from a List or Array in Spark using Scala
- How to use Spark SQL to parse the JSON array of objects
- How to add a json object in to a json array using scala play?
- How to read json data using scala from kafka topic in apache spark
More Query from same tag
- Adding task dependencies in .sbt file
- extracting case classes with scala lift-json when json is variable
- Editor does not contain a main type
- Create Spark Dataframe from SQL Query
- Add List to ListBuffer with foreach
- JSONPath and json4s
- SBT - task to transitively gather subprojects information
- play framework atmosphere
- Filtering and mixing monads in Slick for comprehension and Cats
- Functional way to generate file names in Scala
- Invert map and reduceByKey in Spark-Scala
- how to join dataframes with some similar values and multiple keys / scala
- Optimal way to read out JSON from MongoDB into a Scalatra API
- Using an outer scope variable inside a future is blocking future in scala3
- Efficient way to convert Scala Array to Unique Sorted List
- Accessing Cygwin paths from Scala REPL
- Why are there so many Scala collection view types?
- Seq[AnyVal] returned as type instead of Seq[Int]
- Play JSON: turn a Seq[Reads[JsObject]] into one Reads[JsObject]
- how to do load balancing on remote Actors in Akka?
- Relative frequency of pair of words in scala
- Relation "schema.table" does not exist exception thrown when using slick 3.3.3
- How to update object periodically on Spark workers?
- Can scala implicitly join 2 implicits into an implicit tuple?
- How to restructure code to avoid warning: "Adapting argument list by creating a 2-tuple"
- Running dummy_rocc_test on zed board
- How to safely skip messages using Lagom Kafka Message Broker API?
- Implementing fields in Scala generic classes
- Spark Cassandra Connector: Implement SCD Type 1
- Scala Class Variable Name Hides Method Parameter Name