Importing nested data
You're building an HR dashboard, and the employee data arrives as a nested JSON file. Real-world JSON often contains hierarchical structures, but Tablesaw can automatically flatten these into a tabular format.
Your task is to load the nested JSON, explore its flattened structure, and filter for a specific employee. The JsonReader, JsonReadOptions, and Table classes have been imported for you.
Cet exercice fait partie du cours
Importing Data in Java
Instructions
- Configure the JSON read options with a custom table name.
- Load the JSON file into a table.
- Filter the table to find the employee named "Alice".
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
public class NestedEmployees {
public static void main(String[] args) {
// Configure options with table name
JsonReadOptions options = JsonReadOptions
.____("nested.json")
.____("Employees")
.build();
// Load JSON into table
Table employees = new ____().read(options);
System.out.println("Rows: " + employees.rowCount());
System.out.println("Columns: " + employees.columnCount());
System.out.println("Structure: " + employees.structure());
// Filter for "Alice"
Table alice = employees.____(
employees.stringColumn("name").isEqualTo("____")
);
System.out.println(alice);
}
}