# `Otera.JSON`
[🔗](https://github.com/georgeguimaraes/otera/blob/v0.1.0/lib/otera/json.ex#L1)

JSON with the rules of Python `json`: `dumps/2` for the `tojson` filter, and `decode!/1` to keep the key order of objects.

`dumps/2` gives the same text as Python `json.dumps`, with its options `ensure_ascii`, `indent`, `separators` and `sort_keys`. Floats use the Python `repr()`, so `1.0` stays `1.0`.

# `decode!`

```elixir
@spec decode!(String.t()) :: term()
```

Decodes JSON text into template values. Objects become `Otera.Dict` structs with the key order of the text, like `json.loads` in Python.

Use it to give a template the tool definitions or messages of a JSON request, so that `tojson` prints their keys in the same order as transformers.

    iex> Otera.JSON.decode!(~s({"b": 1, "a": 2}))
    %Otera.Dict{pairs: [{"b", 1}, {"a", 2}]}

# `dumps`

```elixir
@spec dumps(term(), keyword()) :: String.t()
```

Encodes `value` like Python `json.dumps`.

Options: `:ensure_ascii` (default `true`), `:indent` (an integer or a string), `:separators` (a `{item, key}` tuple) and `:sort_keys` (default `false`).

---

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