PtcRunner.Kernel.DeterministicJSON (PtcRunner v0.14.0)

Copy Markdown View Source

Internal deterministic encoder for frozen Kernel metadata and hashes.

Ordinary maps require binary UTF-8 keys or valid public symbol-reference wrappers and are recursively sorted by their normalized key bytes. {:object, pairs} accepts the same key types, preserves an explicit key order for versioned projections, and rejects duplicate normalized keys before a map could erase them. Symbol-reference values are likewise encoded as their display strings. Arrays retain their input order and output contains no insignificant whitespace.

Summary

Types

json_key()

@type json_key() :: binary() | %PtcRunner.Lisp.Format.SymbolRef{name: binary()}

ordered_object()

@type ordered_object() :: {:object, [{json_key(), term()}]}

Functions

encode(value)

@spec encode(term() | ordered_object()) ::
  {:ok, binary()} | {:error, :invalid_json | :duplicate_key}