sirenlint
raw JSON → 0.5.0 verified Fri May 01 auth: no javascript maintenance
A lint tool for validating Siren hypermedia documents against the Siren specification (sirenspec.org). Version 0.5.0 is the latest stable release, but the project appears to be in maintenance mode with infrequent updates. It provides both a CLI for piping/reading Siren JSON files and a programmatic API. Key differentiators: focused solely on Siren validation (no generic JSON/HAL/Collection+JSON support), outputs structured error/warning objects with JSON path information. Alternatives include custom Siren validators or generic JSON schema validators.
Common errors
error TypeError: sirenlint is not a function ↓
cause Using import or expecting a default export; sirenlint is a function via require, not a named export.
fix
Use const validate = require('sirenlint'); instead of import.
error Cannot find module 'sirenlint' ↓
cause Package not installed globally or locally; or using global CLI without installation.
fix
Run npm install sirenlint --save-dev (local) or npm install -g sirenlint (global).
error undefined is not a valid Siren JSON ↓
cause Passing undefined or null to validate().
fix
Ensure input is a valid JSON string before calling validate().
Warnings
gotcha Input must be a string, not a parsed object. If you pass an object, validation may fail or produce unexpected results. ↓
fix Always pass JSON string (e.g., JSON.stringify(yourObject)) to validate().
gotcha CLI always outputs to stdout regardless of errors; exit code is always 0 even with warnings/errors. ↓
fix Check output string for error count or parse the result programmatically; consider using library API for error handling.
deprecated Package uses nomnom for CLI parsing; nomnom is deprecated and may have security issues. ↓
fix Use library API instead of CLI, or fork and replace nomnom with a modern alternative like yargs.
gotcha Validation rules are hardcoded and not configurable; no way to suppress specific warnings or add custom rules. ↓
fix Accept the default validation set or use an alternative validator that supports rule customization.
Install
npm install sirenlint yarn add sirenlint pnpm add sirenlint Imports
- validate wrong
import validate from 'sirenlint';correctconst validate = require('sirenlint'); - ValidationError wrong
import { ValidationError } from 'sirenlint';correctconst { ValidationError } = require('sirenlint'); - ValidationWarning wrong
import { ValidationWarning } from 'sirenlint';correctconst { ValidationWarning } = require('sirenlint');
Quickstart
const fs = require('fs');
const validate = require('sirenlint');
const sirenJson = `{ "class": ["order"], "properties": { "orderNumber": 42 }, "entities": [], "links": [] }`;
const results = validate(sirenJson);
results.forEach(r => {
if (r instanceof validate.ValidationError) {
console.error('ERROR:', r.path, r.message);
} else if (r instanceof validate.ValidationWarning) {
console.warn('WARNING:', r.path, r.message);
}
});