Loading JSON files
You've just joined an e-commerce analytics team, and your first task is to explore the company's product catalog. The data arrives as a JSON file - a format you'll encounter frequently when working with web APIs and modern data sources.
Before diving into analysis, you need to load the JSON data and understand its structure. 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 and build the JSON read options for the file.
- Create a
JsonReaderand load the data into a table. - Display the first three rows of the table.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
public class UnderstandingJSON {
public static void main(String[] args) {
// Configure and build JSON read options
JsonReadOptions options = ____.builder("products.json").____();
// Create JsonReader and load data
Table products = new ____().read(____);
System.out.println("Product Catalog Structure:");
System.out.println("Columns: " + products.columnNames());
System.out.println("Row count: " + products.rowCount());
System.out.println("\nTable structure:");
System.out.println(products.structure());
// Display first three rows
System.out.println("\nFirst few rows:");
System.out.println(products.____(3));
}
}