Size Chart Data Structure

JSON file management, normalization processing, and dynamic mapping with KV store

Size ChartData StructureJSONVercel KVNormalization
3 min read

Data Structure Design

The size chart feature needs to manage numerous size chart data and quickly retrieve the appropriate chart from product information. This page explains the data structure and management methods.

File Structure

Size chart data is managed as JSON files.

File Structure
data/sizecharts/

Directory for size chart data

index.json

Size chart list

*.json

Individual size chart data

File Naming Convention

Size chart IDs follow this naming convention:

outer-
CategoryOuterwear
Examplesouter-men-jacket, outer-women-pants
ws-
CategoryWinter Sports
Examplesws-men-jacket, ws-kids-jacket
cycling-
CategoryCycling
Examplescycling-jacket, cycling-gloves

JSON File Structure

Each size chart JSON file contains an HTML table for display and measurement guides.

{
  "id": "outer-men-jacket",
  "name": "Outerwear: Jacket (Men's)",
  "category": "outerwear",
  "itemType": "jacket",
  "gender": "men",
  "tableHtml": "<table>...</table>",
  "measurementGuide": {
    "chest": "Chest: Measure horizontally at the fullest part",
    "height": "Height: Measure without shoes"
  }
}

Normalization Processing

Since Shopify metafields are prone to notation variations, we perform normalization.

category Normalization

category Evaluation
Convert input to lowercase
Preprocessing
Evaluate by keywords
Classification
Contains ski, winter, snow
→ winter-sports
Contains bicycle, mtb, bike, cycling
→ cycling
Other
→ outerwear (default)

gender Normalization

women, woman, female, lady, ladies
Normalizedwomen
kid, child, junior, kids
Normalizedkids
men, man, male, mens
Normalizedmen
Other
Normalizedunisex

Mapping Data Management

Mappings are managed in two locations, balancing flexibility and stability.

Two-Layer Mapping Structure
lib/sizechart.ts

Default values / Fallback

Vercel KV

Dynamic changes from admin panel

Priority
Size Chart Selection Logic

References KV → Default values in order

Why Two Layers?

  • Default values: Embedded in code ensures service continuity during KV failures
  • Vercel KV: Allows immediate mapping changes from admin panel

KV Key Design

sizechart:mapping:{category}:{productType}:{gender}
  → Size chart ID

sizechart:handle:{handle}
  → Dedicated size chart ID (for handle exceptions)

sizechart:sku:{sku}
  → Dedicated size chart ID (for SKU exceptions)

Examples:

  • sizechart:mapping:outerwear:jackets:menouter-men-jacket
  • sizechart:handle:special-product-2024special-product-chart

API Design

Size chart retrieval is done through an API.

API Call Flow
Product Page
Client
API Call
/api/sizechart/get
Execute Selection Logic
Server
Read JSON File
Data Retrieval
Return Response
Size Chart Data

API Request Example

GET /api/sizechart/get
  ?handle=product-abc-001
  &sku=ABC-001-M
  &category=outerwear
  &productType=jackets
  &gender=men

API Response Example

{
  "success": true,
  "chart": {
    "id": "outer-men-jacket",
    "name": "Outerwear: Jacket (Men's)",
    "tableHtml": "<table>...</table>",
    "measurementGuide": { ... }
  }
}

Caching Strategy

Since size chart data doesn't change frequently, we actively use caching.

JSON Files
Cache LocationServer Memory
DurationLoaded at build time
Mapping Data
Cache LocationVercel KV
DurationNo TTL (explicit updates)
API Response
Cache LocationCDN Edge
Duration60 seconds (stale-while-revalidate)

Summary

The size chart data structure is designed with these key points:

  • JSON File Management: Numerous size charts managed as static files
  • Normalization: Absorbs notation variations to improve mapping accuracy
  • Two-Layer Mapping: Balances flexibility and stability with defaults and KV
  • Caching: Achieves fast response times

Related Topics