# `A2UIAgent.PayloadFixer`
[🔗](https://github.com/a2ui-elixir/a2ui/blob/v0.1.1/umbrella/apps/a2ui_agent/lib/a2ui_agent/payload_fixer.ex#L1)

Reads a JSON payload a model wrote, fixing the mistakes models commonly
make, as the reference SDKs' payload fixer (`parse_and_fix`) does.

    iex> A2UIAgent.PayloadFixer.parse_and_fix(~s({"text": "Hi",}))
    {:ok, [%{"text" => "Hi"}]}

Curly quotes are made straight, raw control characters inside strings
are accepted, and when the payload does not read, trailing commas
before a closing bracket are dropped and it is read again. A single
object comes back wrapped in a list.

The direct JSON parser reads blocks with the more forgiving
`A2UIAgent.DirectJson.JsonReader`; this fixer is for code that wants
the reference's exact rules.

# `parse_and_fix`
*since 0.1.0* 

```elixir
@spec parse_and_fix(String.t()) :: {:ok, [term()]} | {:error, A2UICore.Error.t()}
```

Reads `payload`. Fails with a `:parse` error that says what is wrong,
with a hint for a backslash that is not escaped.

---

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