Adding JSON Schema Validation to the Content‑Automation Pipeline
TL;DR: I introduced a JSON schema validator (AJV) into the CI workflow to catch malformed content files before they reach the publishing scripts. The change stops broken Bluesky posts and keeps metadata.json in sync across all channels.
The Problem
Our content-automation repo generates Markdown and JSON payloads for Medium, Substack, and Bluesky every night. A single typo in a JSON file—like a missing comma or an invalid date string—breaks the downstream publishing step, causing the CI job to fail after the heavy build phase.
The most recent symptom was a Bluesky post with an empty date field, which the publishing script interpreted as undefined and threw:
Error: Invalid post payload – "date" is required (bluesky_en.json line 12) The offending file (content/2026/11/19/content-automation/bluesky_en.json) looked like this in the diff:
+[ + { + "type": "progress", + "text": "Finally fixed the bug in content/2026/11/19/content-automation/bluesky_en.json that was breaking the auto‑generated post dates. Swapped Notice the missing closing quote and the truncated line—this is exactly what slipped through our previous checks because we only linted Markdown files.
What I Tried First
My first instinct was to add a quick grep in the CI script to look for the string "date": "". I also tried running node -c on the JSON files, but node -c only checks syntax, not schema compliance (e.g., required fields, format). Both approaches missed the problem because the file was syntactically valid JSON (the truncation happened after the CI checkout) and the missing date was a logical error, not a syntax error.
The Implementation
1. Define a JSON schema
Create schema/content-schema.json to describe the shape of every platform payload:
{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Content Payload", "type": "object", "properties": { "type": { "type": "string", "enum": ["progress", "announcement", "article"] }, "text": { "type": "string", "minLength": 1 }, "date": { "type": "string", "format": "date-time" } }, "required": ["type", "text", "date"], "additionalProperties": false } The schema enforces that every JSON file must contain a date in ISO‑8601 format, which is exactly what the Bluesky publisher expects.
2. Add a validation script
Add scripts/validate-content.js that walks the content/**/**/*.json tree and validates each file against the schema using AJV:
// scripts/validate-content.js const fs = require('fs'); const path = require('path'); const Ajv = require('ajv'); const ajv = new Ajv({ allErrors: true, strict: false }); const schema = JSON.parse( fs.readFileSync(path.resolve(__dirname, '../schema/content-schema.json'), 'utf-8') ); const validate = ajv.compile(schema); function* walk(dir) { for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { const res = path.resolve(dir, entry.name); if (entry.isDirectory()) yield* walk(res); else if (entry.isFile() && entry.name.endsWith('.json')) yield res; } } let hasError = false; for (const file of walk(path.resolve(__dirname, '../content'))) { const data = JSON.parse(fs.readFileSync(file, 'utf-8')); const ok = validate(data); if (!ok) { console.error(`\n❌ Validation failed for ${file}:`); console.error(validate.errors); hasError = true; } else { console.log(`✅ ${file} is valid`); } } process.exit(hasError ? 1 : 0); 3. Wire the script into package.json
{ "scripts": { "validate:content": "node scripts/validate-content.js", "ci": "npm run lint && npm run test && npm run validate:content && npm run build" } } Now npm run ci will abort early if any JSON payload violates the schema.
4. Update GitHub Actions workflow
Edit .github/workflows/ci.yml to run the new step:
name: CI on: push: branches: [ main ] pull_request: branches: [ main ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up Node uses: actions/setup-node@v3 with: node-version: '20' - run: npm ci - name: Lint & Test run: npm run lint && npm run test - name: Validate content payloads run: npm run validate:content - name: Build run: npm run build 5. Verify with a failing commit
I introduced a deliberately broken bluesky_es.json (missing the date field) and pushed it. The CI output now stops at the validation step:
❌ Validation failed for /content/2026/11/20/content-automation/bluesky_es.json: [ { instancePath: '', schemaPath: '#/required', keyword: 'required', params: { missingProperty: 'date' }, message: "must have required property 'date'" } ] Error: Process completed with exit code 1. No further steps (build, deploy) run, saving minutes of wasted compute and preventing a broken post from ever reaching Bluesky.
Key Takeaway
Schema‑driven validation early in the CI pipeline catches logical content errors (missing fields, wrong formats) that static linting can't detect. It turns a runtime publishing failure into a fast, deterministic CI failure, keeping the multi‑channel pipeline reliable.
What's Next
- Front‑matter validation: Extend the same approach to the Markdown files by defining a YAML schema and using
yaml-schema-validator. - Auto‑fix date formats: Add a small pre‑processor that normalizes any
datestrings to ISO‑8601 before validation, reducing manual edits. - Typed content loader: Generate
Part of my Build in Public series — sharing the real process of building SaaS projects from Playa del Carmen, México.
Repo: zaerohell/content-automation · 2026-11-21
#playadev #buildinpublic