AgentBlueprintProtocol.Json (Agent Blueprint Protocol v1.1.0)

Copy Markdown View Source

This module decodes bounded JSON into an order-preserving tagged value.

Use it when decoding protocol JSON before passing the value to another module.

This module does not authorize operations.

Example

{:ok, value} = AgentBlueprintProtocol.Json.decode(~s({"ready":true}))

Summary

Types

A JSON value represented as a tagged scalar, array, or ordered object.

Functions

Decodes bounded JSON into an order-preserving tagged value.

Types

value()

(since 1.0.0)
@type value() ::
  :null
  | {:boolean, boolean()}
  | {:integer, integer()}
  | {:float, float()}
  | {:string, binary()}
  | {:array, [value()]}
  | {:object, [{binary(), value()}]}

A JSON value represented as a tagged scalar, array, or ordered object.

Functions

decode(input, bounds \\ Bounds.maximum())

(since 1.0.0)
@spec decode(binary(), AgentBlueprintProtocol.Bounds.t() | map()) ::
  {:ok, value()} | {:error, AgentBlueprintProtocol.Error.t()}

Decodes bounded JSON into an order-preserving tagged value.

Example

iex> match?({:ok, {:object, [{"ready", {:boolean, true}}]}}, AgentBlueprintProtocol.Json.decode(~S({"ready":true})))
true
iex> match?({:ok, {:object, [{"ready", {:boolean, true}}]}}, AgentBlueprintProtocol.Json.decode(~S({"ready":true}), %{bytes: 32}))
true