Skip to content

JSON output

When you pass --format json, contextlint writes machine-readable JSON to stdout instead of human-friendly text. Use it for CI annotations, editor extension feedback, and feeding into your own reporting tools.

Terminal window
npx contextlint --format json

The JSON output of the lint (default) subcommand is a flat array of violations.

[
{
"file": "docs/requirements.md",
"line": 12,
"severity": "error",
"message": "Required column \"Status\" not found in table",
"ruleId": "TBL-001"
},
{
"file": "docs/design.md",
"line": 24,
"severity": "warning",
"message": "Empty cell in column \"Status\"",
"ruleId": "TBL-002"
}
]

Each element has these fields:

FieldTypeDescription
filestringRelative path of the file where the violation was found
linenumberLine number of the violation (1-based)
severity"error" / "warning"Severity
messagestringDescription of the violation
ruleIdstringHyphenated rule ID (e.g. TBL-001)

If there are no violations, the output is an empty array [].

JSON output works well for GitHub Actions annotations, or as the payload for Slack / Discord notifications.

The Composite Action shipped with the repository runs contextlint with --format json and converts the results into PR inline annotations. For configuration examples, see CI/CD → GitHub Actions.

A simple example using jq to count violations:

Terminal window
npx contextlint --format json | jq 'length'
# => 2

You can also count violations per rule:

Terminal window
npx contextlint --format json | jq 'group_by(.ruleId) | map({rule: .[0].ruleId, count: length})'

impact, slice, and graph also accept --format json, but their output structure differs from lint. For example output, see Concepts.