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, absolutePath and the two path anchors:
import io.github.quafadas.table.{*, given}
val jsonFromResource = JsonTable.resource("mini-movies.json")
val jsonFromAbsolutePath = JsonTable.absolutePath("/absolute/path/to/file.json")
// Relative to the source file this call sits in
val jsonFromSource = JsonTable.relativeToSource("relative/path/to/file.json")
// Relative to the first ancestor holding a build marker (build.mill, build.sbt, .git, ...)
val jsonFromRoot = JsonTable.projectRoot("data/file.json")