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.
This exercise is part of the course
Importing Data in Java
Exercise 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".
Hands-on interactive exercise
Have a go at this exercise by completing this sample 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);
}
}