json_sentinel 0.2.0
json_sentinel: ^0.2.0 copied to clipboard
Lightweight runtime JSON key and type validation for Dart. No code generation required.
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.
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.