# `TypeSafeAPI.JSON.Encoded`
[🔗](https://github.com/typesend/typesafe_ai/blob/v0.1.0-alpha.3/lib/typesafe_api/json/encoded.ex#L1)

A value that has already been serialized to JSON iodata, and encodes as
those bytes wherever it appears.

`TypeSafeAPI.evaluate_many/4` sends one question set with many states. Keeping
the questions as a `TypeSafeAPI.JSON.OrderedObject` would mean walking and
serializing the whole set once per request; wrapping it here serializes it
once, and every request body splices the same iodata in.

    encoded = TypeSafeAPI.JSON.Encoded.new(TypeSafeAPI.JSON.OrderedObject.new([{"a", 1}]))
    JSON.encode!(%{"questions" => encoded})
    #=> ~s({"questions":{"a":1}})

The original term is kept in `object` so callers can still read the
structure. The two are captured together at construction and never diverge,
because nothing modifies the struct afterwards.

# `t`

```elixir
@type t() :: %TypeSafeAPI.JSON.Encoded{iodata: iodata(), object: term()}
```

# `new`

```elixir
@spec new(term()) :: t()
```

Serializes `object` once and wraps it with its bytes.

# `object`

```elixir
@spec object(t()) :: term()
```

The term that was encoded.

# `to_string`

```elixir
@spec to_string(t()) :: String.t()
```

The cached JSON bytes, as a binary.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
