JsonTable
Scautable will read a JSON file and attempt to infer the structure of the data under the following assumptions:
- A single array of objects at the root of the file,
- No nesting in objects
import io.github.quafadas.table.{*, given}
inline val jsonContent = """[{"active":true,"age":30,"name":"Alice"},{"active":false,"age":25,"name":"Bob"}]"""
// jsonContent: String = "[{\"active\":true,\"age\":30,\"name\":\"Alice\"},{\"active\":false,\"age\":25,\"name\":\"Bob\"}]"
println(JsonTable.fromString(jsonContent).toVector.consoleFormatNt(fansi = false))
// | |active|age| name|
// |-|------|---|-----|
// |0| true| 30|Alice|
// |1| false| 25| Bob|
// |-|------|---|-----|
Other reading methods include resource and absolutePath:
import io.github.quafadas.table.{*, given}
val jsonFromResource = JsonTable.resource("mini-movies.json")
val jsonFromAbsolutePath = JsonTable.absolutePath("/absolute/path/to/file.json")
val jsonFromWorkingDir = JsonTable.pwd("relative/path/to/file.json")