Implement: Content loading — parse JSON card files and validate structure #14

Open
opened 2026-08-20 15:31:19 +02:00 by gaetan · 0 comments
Owner

Wayfinder map: #1
Dependencies: #13 (project scaffolding)

Description

Build the content loading package: parse JSON card files from the content/ directory, validate card structure, and return parsed cards.

Tasks

  • Create internal/content/ package
  • Define Card struct:
    • ID string
    • Type string (values: "qa" for Q&A, "vf" for Vrai/Faux)
    • Question string
    • Answer string
    • Explanation string (optional, can be empty)
    • Category string
    • Tags []string
  • One JSON file per category under content/ (e.g., content/histoire.json)
  • JSON file format: array of Card objects
  • Load function: reads all .json files from content/ directory, parses, validates
  • Validation on load:
    • ID must be non-empty
    • Type must be "qa" or "vf"
    • Question and Answer must be non-empty
    • Category must be non-empty
  • Return parsed cards as []Card
  • Add sample JSON files for testing (can be minimal placeholders)
  • Unit tests for parsing and validation

Acceptance criteria

  • internal/content.Load() reads JSON files and returns valid cards
  • Invalid cards are rejected with clear error messages
  • Unit tests pass for valid and invalid card structures
  • Sample JSON files exist in content/
**Wayfinder map:** #1 **Dependencies:** #13 (project scaffolding) ## Description Build the content loading package: parse JSON card files from the content/ directory, validate card structure, and return parsed cards. ## Tasks - [ ] Create `internal/content/` package - [ ] Define Card struct: - `ID string` - `Type string` (values: "qa" for Q&A, "vf" for Vrai/Faux) - `Question string` - `Answer string` - `Explanation string` (optional, can be empty) - `Category string` - `Tags []string` - [ ] One JSON file per category under `content/` (e.g., `content/histoire.json`) - [ ] JSON file format: array of Card objects - [ ] Load function: reads all `.json` files from content/ directory, parses, validates - [ ] Validation on load: - ID must be non-empty - Type must be "qa" or "vf" - Question and Answer must be non-empty - Category must be non-empty - [ ] Return parsed cards as `[]Card` - [ ] Add sample JSON files for testing (can be minimal placeholders) - [ ] Unit tests for parsing and validation ## Acceptance criteria - `internal/content.Load()` reads JSON files and returns valid cards - Invalid cards are rejected with clear error messages - Unit tests pass for valid and invalid card structures - Sample JSON files exist in content/
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
gaetan/knowledgify#14
No description provided.