Create a simple table in DuckDB and populate a couple of documents with JSON:
duckdb my.db
CREATE TABLE raw_events (id INTEGER, payload JSON);
INSERT INTO raw_events VALUES
(1, '{"user": "alice", "tags": ["a", "b"], "meta": {"score": 42}}'),
(2, '{"user": "bob", "tags": ["c", "b"], "meta": {"score": 38}}');
Select out specific JSON tree elements:
SELECT
id,
payload->>'user' AS user,
(payload->>'$.meta.score')::INT AS score
FROM raw_events;
The base API call for GitHub user events:
https://api.github.com/users/torvalds/events/public
Let's import some of these events into a DuckDB database:
duckdb my.db
CREATE TABLE user_events AS
SELECT * FROM read_json('https://api.github.com/users/torvalds/events/public');
Now inspect that table and count records.
Next, import more records by page:
INSERT INTO user_events
SELECT * FROM read_json('https://api.github.com/users/torvalds/events/public?page=2');
Iterate that command repeatedly through at least page 5.
Inspect your table and count records.
CREATE OR REPLACE TABLE torvalds AS
SELECT id,
type,
actor.login AS actor,
repo.name AS repo,
payload.ref AS ref,
payload.head AS head_sha,
created_at
FROM user_events;