Last updated
Common Use Cases
- Converting database query results to API response format
- Transforming flat JOIN results into nested hierarchical JSON
- Generating TypeScript interfaces from database schemas
- Preparing data exports for JavaScript applications
- Converting snake_case database columns to camelCase JSON properties
- Seeding test data from SQL exports into JSON-based test fixtures
Examples
Example 1: Basic Array of Objects
SQL result (tabular):
id | first_name | last_name | email | created_at
----|------------|-----------|----------------------|--------------------
1 | Alice | Smith | alice@example.com | 2026-01-15 09:00:00
2 | Bob | Jones | bob@example.com | 2026-02-10 14:30:00
3 | Carol | White | carol@example.com | 2026-03-01 11:15:00
JSON output (array of objects, camelCase):
[
{
"id": 1,
"firstName": "Alice",
"lastName": "Smith",
"email": "alice@example.com",
"createdAt": "2026-01-15T09:00:00Z"
},
{
"id": 2,
"firstName": "Bob",
"lastName": "Jones",
"email": "bob@example.com",
"createdAt": "2026-02-10T14:30:00Z"
},
{
"id": 3,
"firstName": "Carol",
"lastName": "White",
"email": "carol@example.com",
"createdAt": "2026-03-01T11:15:00Z"
}
]
Example 2: Nested Object from JOIN Result
SQL JOIN result (flat):
order_id | user_id | user_email | item_id | product_name | quantity | price
---------|---------|-------------------|---------|--------------|----------|------
1 | 1 | alice@example.com | 1 | Widget A | 2 | 29.99
1 | 1 | alice@example.com | 2 | Widget B | 1 | 49.99
2 | 2 | bob@example.com | 3 | Gadget X | 3 | 15.00
JSON output (nested — orders with items array):
[
{
"orderId": 1,
"user": {
"id": 1,
"email": "alice@example.com"
},
"items": [
{ "itemId": 1, "productName": "Widget A", "quantity": 2, "price": 29.99 },
{ "itemId": 2, "productName": "Widget B", "quantity": 1, "price": 49.99 }
]
},
{
"orderId": 2,
"user": {
"id": 2,
"email": "bob@example.com"
},
"items": [
{ "itemId": 3, "productName": "Gadget X", "quantity": 3, "price": 15.00 }
]
}
]
Example 3: Column Name Conversion (snake_case → camelCase)
SQL column names:
user_id, first_name, last_name, email_address,
created_at, updated_at, is_active, profile_picture_url
JSON property names (camelCase):
userId, firstName, lastName, emailAddress,
createdAt, updatedAt, isActive, profilePictureUrl