# JSON Bourne: The Schema Identity

DB Quacks SQL Tutorial · level 34 · chapter 6

Jason Bourne Duck appears in tactical gear. "I've lost my data identity! Complex JSON with nested duck profiles - extract names and favorite foods from deep inside flexible schemas. Navigate the schema-free underworld!"

## Task

Extract duck names and their favorite food from nested JSON data using the 'data/json_duck_profiles.json' file. You will be navigating nested JSON structures using JSON operators.

## Hint

Look for operators that can access nested JSON properties and extract text values.

## Expected result

A table showing duck names and their favorite foods extracted from JSON.

## Tables

### `duck_diaries` (10 rows)

| column | type |
| --- | --- |
| diary_id | BIGINT |
| duck_id | BIGINT |
| entry_date | DATE |
| diary_text | VARCHAR |
| mood | VARCHAR |

### `duck_surveys` (5000 rows)

| column | type |
| --- | --- |
| survey_id | BIGINT |
| duck_id | BIGINT |
| age | BIGINT |
| favorite_food | VARCHAR |
| favorite_pond | BIGINT |
| swimming_rating | BIGINT |
| migration_preference | VARCHAR |
| social_behavior | VARCHAR |
| health_status | VARCHAR |
| activity_level | VARCHAR |
| survey_date | DATE |
| survey_location | BIGINT |

### `ducks` (15 rows)

| column | type |
| --- | --- |
| id | BIGINT |
| name | VARCHAR |
| age | BIGINT |
| species | VARCHAR |
| birth_date | DATE |
| arrival_date | DATE |

### `ponds` (3 rows)

| column | type |
| --- | --- |
| pond_id | BIGINT |
| pond_name | VARCHAR |
| location_lat | DOUBLE |
| location_lng | DOUBLE |
| capacity | BIGINT |
| features | VARCHAR[] |
| amenities | VARCHAR[] |

## Files

### `data/json_duck_profiles.json` (5 rows)

Download: https://dbquacks.com/data/json_duck_profiles.json

| column | type |
| --- | --- |
| profile_id | BIGINT |
| data | STRUCT(duck_id BIGINT, "name" VARCHAR, skills VARCHAR[], preferences STRUCT(favorite_food VARCHAR, favorite_activity VARCHAR, favorite_time VARCHAR), contact_info STRUCT(email VARCHAR, phone VARCHAR)) |

## Data

The tables live in a DuckDB database: https://dbquacks.com/data/databases/tutorial.duckdb

To query it outside the browser, attach it read-only:

```sql
ATTACH 'https://dbquacks.com/data/databases/tutorial.duckdb' AS db (READ_ONLY);
USE db;
```

Play it in the browser: https://dbquacks.com/tutorial/34

## Reference

https://duckdb.org/docs/stable/data/json/json_functions.html
