Attesto.StrictJSON (Attesto v2.28.0)

Copy Markdown View Source

Strict JSON object decoder with duplicate-member rejection and nesting bounds.

RFC 8259 §4 states that object member names SHOULD be unique and notes that implementations disagree when duplicate keys appear. Security-sensitive JSON boundaries (JWS headers and claim sets, JWE protected headers, discovery and metadata documents) must reject duplicate object members at parse time so an input cannot mean one thing to a verifier and another to an intermediary.

Summary

Functions

Decode a JSON binary into a map, rejecting duplicate object member names and inputs that exceed :max_json_depth (default 32).

Decode a JSON binary into any JSON value (object, array, or scalar), rejecting duplicate object member names and inputs that exceed :max_json_depth (default 32) at any nesting level.

Functions

decode(bytes, opts \\ [])

@spec decode(
  term(),
  keyword()
) :: {:ok, map()} | {:error, :invalid_json}

Decode a JSON binary into a map, rejecting duplicate object member names and inputs that exceed :max_json_depth (default 32).

Returns {:ok, map} when the top-level value is a JSON object with no duplicate keys in any nested object, or {:error, :invalid_json} otherwise.

decode_value(bytes, opts \\ [])

@spec decode_value(
  term(),
  keyword()
) :: {:ok, term()} | {:error, :invalid_json}

Decode a JSON binary into any JSON value (object, array, or scalar), rejecting duplicate object member names and inputs that exceed :max_json_depth (default 32) at any nesting level.