Documentation
¶
Overview ¶
Package datajson implements ontos-data-json/1: the named, TOTAL projection of a domain-JSON document to an ontos/data value (docs/spec/ontos-data-json.md).
It is the first-class, importable realization of that projection, driven by the cross-impl conformance lock in vectors/data-json.json. Consumers that need the ontos reading of a JSON value — e.g. domain-separated identity digests — call Project directly instead of re-implementing the walk; a re-implementation is the preimage-drift class this package exists to remove.
The projection is total over the accepted JSON forms and composes the frozen ontos/data primitives (it never re-derives a byte form):
JSON object -> data map (data.EncodeMap) JSON array -> data list (data.EncodeList) JSON string -> utf8-text (data.EncodeText) JSON integer literal -> int (data.EncodeInt, arbitrary precision) JSON true / false -> bool (data.EncodeBool) JSON null -> null() (data.EncodeNull)
A JSON number carrying a fraction or exponent (1.5, 1e3, 1.0) falls in the RESERVED decimal arm, which ontos-data-json/1 does not graduate: Project rejects it path-named rather than coercing to a float or a decimal. Acceptance is by the literal FORM, not the numeric value — 1.0 and 1e3 reject even though they are whole numbers.
Project reads exactly one JSON document; trailing data after it is rejected.
WHY THIS PACKAGE PARSES JSON ITSELF, instead of encoding/json ------------------------------------------------------------- Two acceptance decisions are destroyed by the stock decoder before the projection can see them:
The number LITERAL. Acceptance is decided on the literal form (1e3 vs 1000), which json.Decoder.UseNumber() happens to preserve — that alone once kept encoding/json viable here.
String FIDELITY. encoding/json substitutes U+FFFD for invalid UTF-8 and for unpaired \uXXXX surrogate escapes while decoding, and then SUCCEEDS. U+FFFD is admissible, so the result is a well-formed value whose digest is not the digest of the input — a producer succeeding with a DIFFERENT admissible datum, which ontos-data.md §4.1 law 2 forbids outright (ontos-internal#216). This projection exists to produce identity digests; a silent preimage substitution is the worst outcome available and is invisible at every layer.
The reader below therefore accepts exactly RFC 8259 and nothing more, mirroring the TS peer's reader: number literals are captured verbatim, string content bytes are copied verbatim, and an unpaired surrogate escape is decoded to its WTF-8 bytes — which no valid UTF-8 string contains — so the walk can reject it path-named with the reason vectors/data-json.json pins, instead of silently reading a different string. Raw invalid UTF-8 inside a string literal likewise survives to the walk, where data.EncodeText refuses it (spec §4.1).
Index ¶
Constants ¶
const MaxDepth = 10000
MaxDepth is this face's nesting-depth ceiling: the depth of the deepest object/array nesting Project reads before returning a *LimitError. It restores the protection the stock decoder carried (encoding/json capped at 10000) that the own-reader move dropped (ontos-internal#236). Conformance requires accepting at least the spec's floor of 512; the ceiling itself is per-face and never pinned by vectors.
Variables ¶
This section is empty.
Functions ¶
func Project ¶
func Project(raw json.RawMessage) (core.Value, error)
Project reads a single domain-JSON document and returns its ontos-data-json/1 value. See the package doc for the arm table and the reserved decimal arm. On any rejected form it returns an *Error carrying the JSONPath of the offending node. Repeated object members collapse last-wins; see ProjectWith to refuse them.
func ProjectWith ¶
ProjectWith is Project with Options. With the zero Options it is Project; with DuplicateKeysReject it additionally returns a *DuplicateKeyError for a document that repeats an object member. Every other outcome — the accepted value and its bytes, the path-named *Error rejections, the *LimitError class — is identical between the two modes.
Types ¶
type DuplicateKeyError ¶
DuplicateKeyError is the strict-mode refusal: under DuplicateKeysReject the object at the parent of Path repeated the member Key. It is a source-admission class like Error — the document was refused, not a resource bound hit — and deliberately a distinct type from both Error (the /1 domain rejections, whose reasons the vectors pin verbatim) and LimitError (the resource-limit class), so a caller can tell "the admission policy it opted into refused this" from "the profile has no reading for it". The reader stops at the FIRST repeat it meets in source order; Path names that member (e.g. `$.items[1].id`) and Key is the name as decoded.
func (*DuplicateKeyError) Error ¶
func (e *DuplicateKeyError) Error() string
type DuplicateKeys ¶
type DuplicateKeys int
DuplicateKeys selects how ProjectWith treats a JSON object that repeats a member name (ontos-data-json.md §"The projection", *Duplicate object keys*).
const ( // DuplicateKeysLastWins is the ontos-data-json/1 default and what [Project] // does: repeated members collapse to the LAST occurrence at the reader, before // any ontos/data value is built. DuplicateKeysLastWins DuplicateKeys = iota // DuplicateKeysReject refuses the document at the first repeated member with a // [*DuplicateKeyError]. It is a stricter SOURCE-ADMISSION policy over the same // mapping, not a different reading: every document it accepts projects to // exactly the value (and bytes) [Project] emits for it. Names collide on their // exact decoded content — an escaped and a literal spelling of the same name // are one name; two names that differ in bytes are two names, even when // canonically equivalent (no Unicode normalization, ontos-data §5.2). Ontos // ontos-internal#322. DuplicateKeysReject )
type Error ¶
Error is a projection failure carrying the JSONPath of the offending node ($ for the root, $.key for an object member, $[i] for an array element) and a stable, spec-worded reason. The reason strings are part of the ontos-data-json/1 conformance surface — vectors/data-json.json pins them — so they are formatted here to match the lock byte-for-byte.
type LimitError ¶
type LimitError struct {
Limit int
}
LimitError reports that the document exceeded this face's nesting-depth ceiling (an IMPLEMENTATION BOUND, ontos-data-json/1 resource-limit posture, ontos-internal#236). It is deliberately a distinct type from Error: a depth limit does not say the document is inadmissible under /1 — another conformant face with a higher ceiling may accept it — so conflating the two would put the limit into the profile's semantics. The spec's floor is 512; this face's ceiling is MaxDepth. Mirrors ontos-codec's decode-limit class (limit_exceeded, never a domain error).
func (*LimitError) Error ¶
func (e *LimitError) Error() string
type Options ¶
type Options struct {
DuplicateKeys DuplicateKeys
}
Options tunes ProjectWith. The zero value is exactly Project.