# `LlmCall.JSON`
[🔗](https://github.com/gilbertwong96/llm_call/blob/main/lib/llm_call/json.ex#L1)

The JSON seam.

`Config.json` is a module. The default is Elixir's built-in `JSON`, and any
module exposing either the tagged or the bang API can be configured:

  * tagged: `encode/1` and `decode/1` returning `{:ok, value}` / `{:error, _}`
    (Torque, Jason, Poison, `LlmCall.JSON`);
  * bang: `encode!/1` and `decode!/1` (Elixir's `JSON`).

The facade functions `encode/2` and `decode/2` dispatch on what the module
exports and normalize the result to a tagged tuple, so a codec never raises on
a malformed payload. Configure the module at compile time with
`config :llm_call, json_library: Torque`, or per client with
`json_library:`.

A few wire fields are themselves JSON strings: tool-call arguments on OpenAI
Chat, and streamed function calls on Gemini. A codec therefore needs a JSON
implementation, and the caller may want a different one (Jason, a stricter
encoder, a wrapped implementation with metrics).

# `decode`

```elixir
@callback decode(String.t()) :: {:ok, term()} | {:error, term()}
```

Decodes a JSON binary.

# `encode`

```elixir
@callback encode(term()) :: {:ok, String.t()} | {:error, term()}
```

The tagged adapter used by `LlmCall.JSON` itself, backed by Elixir `JSON`.

# `decode`

# `decode`

```elixir
@spec decode(module(), String.t()) :: {:ok, term()} | {:error, term()}
```

Decodes a binary with the configured module.

# `encode`

# `encode`

```elixir
@spec encode(module(), term()) :: {:ok, String.t()} | {:error, term()}
```

Encodes a term with the configured module.

---

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