# `Weavr.JSON`
[🔗](https://github.com/iamkanishka/weavr/blob/main/lib/weavr/json.ex#L1)

Minimal, dependency-free JSON encoder/decoder.

The `weavr` package intentionally ships with zero runtime dependencies
(see the package README for rationale). This module implements just
enough of RFC 8259 to encode request bodies and decode response bodies
for the Weavr API: objects, arrays, strings, numbers, booleans, and
null, with UTF-8 string handling.

If your application already depends on `Jason`, `Poison`, or OTP 27's
built-in `:json`, you can override JSON handling by configuring:

    config :weavr, json_library: Jason

Any module implementing `encode!/1` and `decode!/1` with the same
contract as `Jason` works as a drop-in replacement.

## Known limitation

`\uXXXX` escapes for codepoints above U+FFFF (i.e. those requiring a
UTF-16 surrogate pair, like many emoji) are not supported when
written as an explicit escape sequence in the JSON source — only
literal UTF-8 bytes for those characters decode correctly. This is
vanishingly rare for the JSON Weavr's API actually returns (it
controls its own encoder), but if you need full RFC 8259 fidelity,
configure `Jason` as above.

# `json`

```elixir
@type json() ::
  nil
  | boolean()
  | number()
  | binary()
  | [json()]
  | %{optional(binary()) =&gt; json()}
```

# `decode!`

```elixir
@spec decode!(binary()) :: json()
```

Decodes a JSON binary into Elixir terms (maps, lists, numbers,
binaries, booleans, `nil`). Object keys are always returned as strings.

Raises `Weavr.JSON.DecodeError` on malformed input.

# `encode!`

```elixir
@spec encode!(term()) :: binary()
```

Encodes an Elixir term into a JSON binary.

Maps with atom keys are supported; atom keys are converted to strings.
Raises `Weavr.JSON.EncodeError` on values that cannot be represented.

---

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