Skip to content

gray-matter YAML date coercion breaks JSON Schema string validation #79

@mindsocket

Description

@mindsocket

Problem

When markdown frontmatter contains an unquoted ISO date like:

date: 2026-03-31

parses it as a JavaScript Mon Apr 6 12:20:39 AEST 2026 object, not a string. This fails JSON Schema validation against properties:

Reproduction

  1. Create a markdown file with (unquoted) in frontmatter
  2. Validate against a schema where the property is
  3. Validation fails — the value is a Date object, not a string

Proposed fix

JSON Schema supports a annotation on string types: https://json-schema.org/understanding-json-schema/reference/type#format

We should:

  1. **Support ** (and ) on string properties in schema definitions
  2. Coerce Date objects from gray-matter to ISO strings during parsing, so becomes before validation
  3. Validate the coerced string against the format annotation (e.g. ISO 8601 pattern)
  4. This should happen in the markdown plugin's read phase, not in the schema validator — fix the data at the boundary

Common frontmatter fields affected: date, published_date, due_date, deadline, created, updated.

Scope

  • Coercion should only apply when the schema declares the property as with a date-related format — we don't want to silently coerce strings in other contexts
  • Consider whether to also coerce unquoted dates that aren't Date objects (gray-matter usually handles this, but edge cases with different YAML parsers may vary)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions