I read a JSON file and use json4s to parse JSON.
How I can sort an array of JObject that I read from the file?
package org.example
import org.json4s._
import org.json4s.native.JsonMethods._
object Main extends App {
val file = scala.io.Source.fromURL("https://raw.githubusercontent.com/mledoze/countries/master/countries.json")
val text = file.mkString
val json = parse(text)
val countries = json.children
countries.sortBy(...)
}
Each country has a field "area" and I need to sort the list by this field. I don't know how to use sortBy in this situation because the country is not just an object of some class. This is JObject and the field "area" has a type JInt.
Can you help me? Or maybe do you know other solution?