Expand description
Checks files in the JSON family for syntax errors, duplicate keys and the rules of each dialect: JSON, I-JSON, JSONC, JWCC (HuJSON), JSON5 and JSON Lines.
use jsonvet::{check, Config, Dialect, Rule};
let text = "{\n // port\n \"port\": 80,\n \"port\": 8080,\n}\n";
let report = check(text, &Config::new(Dialect::Json5));
let problem = &report.problems()[0];
assert_eq!(problem.rule(), Rule::DuplicateKey);
assert_eq!(problem.to_string(), "duplicate key $.port");
let at = report.location(problem.offset());
assert_eq!((at.line, at.column), (4, 3));check never panics and has no error mode: the problems in the text are its output.
Structs§
- Config
- What to check: a dialect, and any rules whose severity differs from the dialect’s default.
- Location
- A 1-based line and column. Lines end at LF, CR, CRLF, U+2028 and U+2029, as JSON5 defines them; columns count Unicode code points from the start of the line.
- Problem
- One problem in a file: what is wrong, where, and how much it matters.
- Report
- The problems found in one text, in document order.
- Unknown
Dialect - The error for a dialect name jsonvet does not know.
- Unknown
Rule - The error for a rule id jsonvet does not know.
Enums§
- Dialect
- A member of the JSON family. Each one only adds syntax to the one before it, in the order JSON, JSONC, JWCC, JSON5; I-JSON is JSON with stricter content rules, and JSON Lines is one JSON value per line.
- Rule
- What jsonvet checks. Every problem belongs to one rule.
- Severity
- How much a problem matters. An ignored (
Off) rule is not checked at all.
Functions§
- check
- Check one text and return every problem in it, in document order. Checking stops at the first syntax error; problems found before it stay in the report.