Overview
The JSON output format provides machine-readable, structured output suitable for integration with other tools, CI/CD systems, and automated workflows. Vale outputs alerts as a JSON object with file paths as keys and arrays of alert objects as values.Use JSON output when you need to parse Vale’s results programmatically or integrate with other tools in your workflow.
Usage
Enable JSON output with the--output flag:
Output Structure
The JSON output is an object where:- Keys: File paths (strings)
- Values: Arrays of alert objects
Alert Object Fields
Each alert object in the arrays contains the following fields:The name of the rule that generated this alert (e.g., “Vale.Spelling”, “Google.Acronyms”).
Additional context or explanation for why this alert is meaningful. May be empty.
The line number where the issue was found (1-indexed).
A URL to reference material or documentation about this rule. May be empty.
The human-readable alert message describing the issue.
The severity level of the alert. One of:
"error": Critical issues that cause Vale to exit with a non-zero status"warning": Important issues that should be addressed"suggestion": Optional improvements
A two-element array
[start, end] indicating the column positions of the match within the line (0-indexed).The actual text that triggered the alert.
Some fields like
Offset, Limit, and Hide are excluded from JSON output (marked with json:"-" in the source code).Implementation Details
The JSON output is generated by thePrintJSONAlerts function in cmd/vale/json.go:10-23:
The JSON output is formatted with 2-space indentation for readability. Alerts are sorted by position before being added to the output.
Exit Code Behavior
When using JSON output, Vale’s exit code follows the same rules as other formats:- Exit 0: No errors found (warnings and suggestions are OK)
- Exit 1: One or more errors found
Integration Examples
Using jq to Filter Results
Extract only errors usingjq:
Count Total Alerts
Extract All Error Messages
Group by Severity
Common Use Cases
CI/CD Integration
Parse JSON output in your CI pipeline to create custom reports:GitHub Actions Example
IDE Integration
Many IDEs and text editors use JSON output to display inline linting results. The structured format makes it easy to:- Highlight issues in the editor
- Show tooltips with error messages
- Provide quick-fix actions based on the
Actionfield
Custom Reporting
Generate custom HTML, Markdown, or other report formats by parsing the JSON output:Node.js Example
Comparison with Other Formats
| Feature | JSON | CLI | Line |
|---|---|---|---|
| Human-readable | ❌ | ✅ | ✅ |
| Machine-parsable | ✅ | ❌ | ⚠️ |
| Includes colors | ❌ | ✅ | ❌ |
| Shows Action hints | ✅ | ❌ | ❌ |
| Includes metadata | ✅ | ⚠️ | ❌ |
| File grouping | ✅ | ✅ | ❌ |
Related Options
- Use
--output=CLIfor human-readable output - Use
--output=linefor simple line-based output - Use
--sortto sort results by file path before JSON encoding - Use custom templates for complete control over output format