UNPKG

agentfootprint

Version:

The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.

38 lines (37 loc) • 1.57 kB
/** * strictJson — ONE reading of a JSON text, with every ambiguity refused. * * `JSON.parse` resolves ambiguity silently: a duplicated key keeps its LAST * value, while another reader may keep the first. A check that reads a body one * way and a consumer that reads it another is a parser differential — a crafted * answer passes the check and is used as something else. So the transport reads * an answer once, here, refusing what two readers could disagree on, and hands * the client the canonical re-serialization of exactly the value it checked. * * Refused, by name: a duplicated object key, trailing data after the value, a * leading byte-order mark, nesting deeper than {@link MAX_DEPTH}, a number * out of range (its re-serialization would be `null`), and anything that is * not RFC 8259 JSON. * * Objects are built with own properties only (a `__proto__` key is data, never * a prototype). * * Pattern: recursive-descent parser. Role: outer ring, the one reader. */ /** Why a text was refused. */ export declare class AmbiguousJsonError extends Error { readonly reason: string; constructor(reason: string); } /** How deep a value may nest. */ export declare const MAX_DEPTH = 256; /** A JSON value, as read. */ export type JsonValue = null | boolean | number | string | readonly JsonValue[] | { readonly [key: string]: JsonValue; }; /** * The one value `text` holds. * * @throws AmbiguousJsonError when the text is not exactly one unambiguous value. */ export declare function parseStrictJson(text: string): JsonValue;