# `Payzum.JSON`
[🔗](https://github.com/payzum-dev/payzum-elixir/blob/main/lib/payzum/json.ex#L1)

JSON that does not silently round money.

The payments surface returns monetary fields as JSON numbers, frozen for
NowPayments compatibility. Decoding them into floats loses digits
(`0.123456789012345678` becomes `0.12345678901234568`) with no error, and
Elixir's standard library has no JSON decoder at all before 1.18.

So this module parses by hand and keeps every number as the exact text between
two separators, and it validates a literal against a strict grammar before it
emits one unquoted.

# `decimal?`

```elixir
@spec decimal?(term()) :: boolean()
```

Whether a string is a plain JSON number literal.

# `decode!`

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

Decode a JSON object, keeping every number as its exact source text.

Raises `Payzum.Errors.Validation` when the payload is not a JSON object.

# `encode_exact!`

```elixir
@spec encode_exact!(map(), [String.t()]) :: binary()
```

Encode a flat payload, emitting the named fields as JSON numbers with every
supplied digit.

Raises `Payzum.Errors.Validation` when a value cannot be emitted safely.

# `positive_decimal?`

```elixir
@spec positive_decimal?(term()) :: boolean()
```

Whether a string is a decimal literal greater than zero.

Decided on the mantissa, so `0e10` is not mistaken for a positive amount.

---

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