json_sentinel 0.4.0
json_sentinel: ^0.4.0 copied to clipboard
Lightweight runtime JSON validation for Dart. Configurable logger, redaction, and batch validation — routes failures to any error reporter. No code generation.
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
Unreleased #
0.4.0 - 2026-06-03 #
Added #
CONTRIBUTING.md— contribution guide covering prerequisites, local CI commands, code standards, and CHANGELOG update instructions.SECURITY.md— security policy with supported versions and private vulnerability reporting process.CODE_OF_CONDUCT.md— Contributor Covenant v2.1.- GitHub issue templates (
bug_report.yml,feature_request.yml) using YAML issue forms. .github/pull_request_template.md— PR checklist aligned with CI requirements.- API documentation deployed to GitHub Pages at
https://igeetheron.github.io/json-sentinel/on every push tomain. - Codecov coverage reporting with badge; coverage collected on every CI run.
validateList()— validates a bareList<dynamic>returned directly fromjsonDecode. Non-Mapitems at index N produce aJsonValidationResult.failurecounted infailureIndiceswith a descriptive message, rather than throwing a cast error. Accepts the same optional parameters asvalidateBatch(), includingwarnUnexpected,validators,optional,strict,escalate, andgeneratePreviews. Compatible withtryFromJson-style guards viabatch.isValidorbatch.failureIndices.warnUnexpectedparameter (bool, defaultfalse) onvalidate(),validateBatch(), andvalidateList(): logs unexpected keys as warnings without failing validation —result.isValidremainstrue. Intended for APIs that add fields in minor versions so teams are notified of contract drift without breaking the app. Mutually exclusive withstrict(asserted in debug mode); warning log entries always useescalate: false.validatorsparameter (Map<String, bool Function(Object?)>?) onvalidate(),validateBatch(), andvalidateList(): per-key predicate functions for value-level checks run after type validation passes for each key. A predicate returningfalseadds a bullet error identifying the key. Predicates are skipped for absent optional keys and for keys that already failed type validation.
Changed #
pubspec.yaml: addeddocumentation:URL and updated description to vendor-agnostic language.- README: added Codecov and API docs badges; linked Contributing, Security, and Code of Conduct in Additional information.
0.3.0 - 2026-06-02 #
Added #
parentContextparameter (String?) onvalidate(): when provided, log output andextras['context']use the full chained path'$parentContext > $context', making it possible to locate failing nested models by call site (e.g.[UserPage.data[2] > MetaModel]).redactKeys(Set<String>?) andredactionPlaceholder(String, default'[REDACTED]') parameters onconfigure()andsilence(). Top-level JSON field values whose keys appear inredactKeysare replaced with the placeholder before anyjson_previeworitem_previewssnapshot is encoded and forwarded to Sentry/Crashlytics — the validated data itself is never modified.
Changed #
- Added
loggingandobservabilitytopics topubspec.yamlfor better pub.dev discoverability.
0.2.0 - 2026-05-29 #
Added #
JsonSentinel.validateBatch()— validates a list ofMap<String, dynamic>payloads against a shared schema and emits a single consolidated log entry covering all failures, preventing one Sentry/Crashlytics event per failure when validating API response lists. Accepts the sameoptional,strict,escalate, andcontextparameters asvalidate()(including the same'UnknownModel'default forcontext). AcceptsgeneratePreviews: falseto skip per-item JSON serialisation for high-volume batches. Returns aBatchValidationResult.BatchValidationResult— result type forvalidateBatch(). Fields:isValid(true only when every item passed),results(oneJsonValidationResultper input item in order),failureCount, andfailureIndices(zero-based indices of failing items). All list fields are unmodifiable.validateBatch()logger extras include'context','failure_count'(int),'total_count'(int), and'item_previews'— aList<String>of truncated JSON previews for each failing item infailureIndicesorder.item_previewsis absent whengeneratePreviews: falseis passed.
Changed #
JsonValidationResult.failure()now asserts in debug mode that theerrorslist is non-empty. A failure result with no errors is semantically contradictory. Callers passingfailure([])will receive anAssertionErrorin debug builds (includingdart test); release builds are unaffected.verbose: truenow emits adart:developertrace on every failingvalidate()andvalidateBatch()call in addition to the existing passing-call traces. Failures are now visible in DevTools Logging even when a Sentry/Crashlytics logger is registered.
0.1.1 - 2026-05-28 #
Fixed #
- Corrected repository and issue tracker URLs to point to
IgeeTheron/json-sentinel.
0.1.0 - 2026-05-28 #
Added #
JsonSentinel.validate()— validates aMap<String, dynamic>against an expected key/type schema at runtime without code generation. Collects all errors before logging so callers always see the full picture in a single log entry.JsonValidationResult— structured result returned byvalidate(), with anisValidflag and an unmodifiableerrorslist for programmatic access.JsonLogFntypedef — function signature for the logging callback. Carriesmessage,stackTrace,extras(includingcontextlabel andjson_preview), andescalatehint.JsonSentinel.configure()— registers aJsonLogFnfor all validation failures. Asserts in debug mode if called more than once; first registration wins in release.JsonSentinel.silence()— no-op alternative toconfigure(); suppresses all log output for purely programmatic use viaresult.errors. Mutually exclusive withconfigure().JsonSentinel.loggergetter — exposes the currently configuredJsonLogFn?;nulluntilconfigure()orsilence()is called.JsonSentinel.resetLoggerForTesting()— resets the logger and verbose flag to their initial state; for use in testtearDown.contextparameter onvalidate()— labels each log entry and thecontextextras key with the model name for searchable Sentry/Crashlytics context. Defaults to'UnknownModel'.optionalparameter onvalidate()— keys marked optional are skipped when absent but still type-checked when present.strictmode onvalidate()— flags unexpected keys not declared in the schema.escalateparameter onvalidate()— per-call hint to the logger for elevated capture (e.g. a Sentry event rather than a breadcrumb). Defaults tofalse.- Nullable fields and union types via the
expectedTypestype-list syntax:[String, null]for nullable,[int, double]for unions,nullor[]for existence-only checks. verboseparameter onconfigure()andsilence()— enables trace-leveldart:developerlogs in debug mode: a confirmation on initialisation, a success trace on every passingvalidate()call, and a diagnostic when JSON serialisation fails.- Fallback logging via
dart:developerwhen no logger is configured; suppressed in release builds — always callconfigure()orsilence()in production code. - Zero runtime dependencies — pure Dart, works in Flutter, server, and CLI projects.