# `Redis.Commands.JSON`
[🔗](https://github.com/joshrotenberg/redis_ex/blob/v0.7.1/lib/redis/commands/json.ex#L1)

Command builders for RedisJSON operations (Redis 8+ / RedisJSON module).

Provides pure functions for storing, retrieving, and manipulating JSON
documents inside Redis. Supports the full JSON.* command set including
object, array, string, and numeric operations.

All path arguments default to `"$"` (JSONPath root). Values passed to
mutating functions are automatically encoded via `JSON.encode!/1` unless
the `raw: true` option is given.

Every function returns a command list for use with `Redis.command/2` or
`Redis.pipeline/2`.

## Examples

    # Store a JSON document
    Redis.command(conn, JSON.set("user:1", %{name: "Alice", age: 30}))

    # Read specific paths from a document
    Redis.command(conn, JSON.get("user:1", paths: ["$.name", "$.age"]))

    # Append elements to a nested array
    Redis.command(conn, JSON.arrappend("user:1", ["reading", "hiking"], "$.hobbies"))

# `arrappend`

```elixir
@spec arrappend(String.t(), [term()], String.t()) :: [String.t()]
```

JSON.ARRAPPEND — append values to an array.

# `arrindex`

```elixir
@spec arrindex(String.t(), term(), String.t()) :: [String.t()]
```

JSON.ARRINDEX — find index of a value in an array.

# `arrinsert`

```elixir
@spec arrinsert(String.t(), non_neg_integer(), [term()], String.t()) :: [String.t()]
```

JSON.ARRINSERT — insert values at an index.

# `arrlen`

```elixir
@spec arrlen(String.t(), String.t()) :: [String.t()]
```

JSON.ARRLEN — get array length.

# `arrpop`

```elixir
@spec arrpop(String.t(), String.t(), integer()) :: [String.t()]
```

JSON.ARRPOP — pop from an array (default: last element).

# `arrtrim`

```elixir
@spec arrtrim(String.t(), non_neg_integer(), integer(), String.t()) :: [String.t()]
```

JSON.ARRTRIM — trim an array to [start, stop].

# `clear`

```elixir
@spec clear(String.t(), String.t()) :: [String.t()]
```

JSON.CLEAR — clear arrays/objects at a path (set to empty).

# `del`

```elixir
@spec del(String.t(), String.t()) :: [String.t()]
```

JSON.DEL — delete a path from a key.

# `get`

```elixir
@spec get(
  String.t(),
  keyword()
) :: [String.t()]
```

JSON.GET — get JSON value(s) at one or more paths.

    JSON.get("key")
    JSON.get("key", paths: ["$.name", "$.age"])

# `merge`

```elixir
@spec merge(String.t(), term(), keyword()) :: [String.t()]
```

JSON.MERGE — merge a JSON value into an existing key.

# `mget`

```elixir
@spec mget([String.t()], String.t()) :: [String.t()]
```

JSON.MGET — get a path from multiple keys.

# `numincrby`

```elixir
@spec numincrby(String.t(), number(), String.t()) :: [String.t()]
```

JSON.NUMINCRBY — increment a number at a path.

# `nummultby`

```elixir
@spec nummultby(String.t(), number(), String.t()) :: [String.t()]
```

JSON.NUMMULTBY — multiply a number at a path.

# `objkeys`

```elixir
@spec objkeys(String.t(), String.t()) :: [String.t()]
```

JSON.OBJKEYS — get object keys at a path.

# `objlen`

```elixir
@spec objlen(String.t(), String.t()) :: [String.t()]
```

JSON.OBJLEN — get number of keys in an object.

# `set`

```elixir
@spec set(String.t(), term(), keyword()) :: [String.t()]
```

JSON.SET — set a JSON value at a path.

Value is auto-encoded to JSON. Pass a raw JSON string with `raw: true`.

    JSON.set("key", %{a: 1})
    JSON.set("key", %{a: 1}, path: "$.nested")
    JSON.set("key", ~s({"a":1}), raw: true)
    JSON.set("key", %{a: 1}, nx: true)   # only set if doesn't exist
    JSON.set("key", %{a: 1}, xx: true)   # only set if exists

# `strappend`

```elixir
@spec strappend(String.t(), String.t(), String.t()) :: [String.t()]
```

JSON.STRAPPEND — append to a string at a path.

# `strlen`

```elixir
@spec strlen(String.t(), String.t()) :: [String.t()]
```

JSON.STRLEN — get string length at a path.

# `toggle`

```elixir
@spec toggle(String.t(), String.t()) :: [String.t()]
```

JSON.TOGGLE — toggle boolean at a path.

# `type`

```elixir
@spec type(String.t(), String.t()) :: [String.t()]
```

JSON.TYPE — get the JSON type at a path.

---

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