This project demonstrates how to:
- Flatten nested JSON data.
- Create a BigQuery table with a specified schema.
- Load the flattened JSON data into the BigQuery table.
project-directory/
├── bigquery/
│ ├── createTable.js # Script to create a BigQuery table
│ ├── loadData.js # Script to load flattened JSON data into the table
│ ├── flattenJSON.js # Utility function to flatten nested JSON
│ ├── test.js # Test script for JSON flattening functionality
├── data/
│ ├── sampleData.json # Example JSON file with nested data
├── package.json # Node.js project configuration
├── README.md # Documentation for the project
This structure organizes the project, ensuring reusability and easy maintenance.
-
Install dependencies:
npm install
-
Set the GOOGLE_APPLICATION_CREDENTIALS environment variable:
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your-service-account-key.json"
-
Run the scripts:
- Create the BigQuery table:
npm run create-table
- Load data into the table:
npm run load-data
- Create the BigQuery table:
To verify the JSON flattening functionality:
node bigquery/test.jsThis will output the flattened structure of the sample JSON data, allowing you to verify the transformation before loading into BigQuery.