# `JsonRemedy.Context.JsonContext`
[🔗](https://github.com/nshkrdotcom/json_remedy/blob/v0.2.1/lib/json_remedy/context/json_context.ex#L1)

Centralized context tracking for JSON repair operations.

This module provides state management for tracking the current parsing context,
which enables context-aware repair decisions across all layers. It tracks
whether we're in an object key, object value, array, or string context.

# `context_value`
[🔗](https://github.com/nshkrdotcom/json_remedy/blob/v0.2.1/lib/json_remedy/context/json_context.ex#L10)

```elixir
@type context_value() :: :root | :object_key | :object_value | :array
```

# `t`
[🔗](https://github.com/nshkrdotcom/json_remedy/blob/v0.2.1/lib/json_remedy/context/json_context.ex#L12)

```elixir
@type t() :: %JsonRemedy.Context.JsonContext{
  current: context_value(),
  in_string: boolean(),
  position: non_neg_integer(),
  stack: [context_value()],
  string_delimiter: String.t() | nil
}
```

# `can_apply_repair?`
[🔗](https://github.com/nshkrdotcom/json_remedy/blob/v0.2.1/lib/json_remedy/context/json_context.ex#L226)

```elixir
@spec can_apply_repair?(t(), atom()) :: boolean()
```

Determines if a repair can be applied in the current context.

String delimiter repairs are allowed when in strings, but most other
repairs should be avoided to prevent corrupting string content.

## Examples

    iex> context = JsonRemedy.Context.JsonContext.new()
    iex> JsonRemedy.Context.JsonContext.can_apply_repair?(context, :quote_normalization)
    true

    iex> string_context = JsonRemedy.Context.JsonContext.enter_string(context, "\"")
    iex> JsonRemedy.Context.JsonContext.can_apply_repair?(string_context, :quote_normalization)
    false
    iex> JsonRemedy.Context.JsonContext.can_apply_repair?(string_context, :string_delimiter)
    true

# `context_stack_depth`
[🔗](https://github.com/nshkrdotcom/json_remedy/blob/v0.2.1/lib/json_remedy/context/json_context.ex#L202)

```elixir
@spec context_stack_depth(t()) :: non_neg_integer()
```

Returns the depth of the context stack.

## Examples

    iex> context = JsonRemedy.Context.JsonContext.new()
    iex> JsonRemedy.Context.JsonContext.context_stack_depth(context)
    0

    iex> nested = %JsonRemedy.Context.JsonContext{stack: [:root, :array]}
    iex> JsonRemedy.Context.JsonContext.context_stack_depth(nested)
    2

# `enter_string`
[🔗](https://github.com/nshkrdotcom/json_remedy/blob/v0.2.1/lib/json_remedy/context/json_context.ex#L112)

```elixir
@spec enter_string(t(), String.t()) :: t()
```

Enters string parsing context with the given delimiter.

## Examples

    iex> context = JsonRemedy.Context.JsonContext.new()
    iex> string_context = JsonRemedy.Context.JsonContext.enter_string(context, "\"")
    iex> string_context.in_string
    true
    iex> string_context.string_delimiter
    "\""

# `exit_string`
[🔗](https://github.com/nshkrdotcom/json_remedy/blob/v0.2.1/lib/json_remedy/context/json_context.ex#L130)

```elixir
@spec exit_string(t()) :: t()
```

Exits string parsing context.

## Examples

    iex> context = %JsonRemedy.Context.JsonContext{in_string: true, string_delimiter: "\""}
    iex> exited = JsonRemedy.Context.JsonContext.exit_string(context)
    iex> exited.in_string
    false
    iex> exited.string_delimiter
    nil

# `in_string?`
[🔗](https://github.com/nshkrdotcom/json_remedy/blob/v0.2.1/lib/json_remedy/context/json_context.ex#L183)

```elixir
@spec in_string?(t()) :: boolean()
```

Checks if the context is currently inside a string.

## Examples

    iex> context = JsonRemedy.Context.JsonContext.new()
    iex> JsonRemedy.Context.JsonContext.in_string?(context)
    false

    iex> string_context = JsonRemedy.Context.JsonContext.enter_string(context, "\"")
    iex> JsonRemedy.Context.JsonContext.in_string?(string_context)
    true

# `new`
[🔗](https://github.com/nshkrdotcom/json_remedy/blob/v0.2.1/lib/json_remedy/context/json_context.ex#L49)

```elixir
@spec new() :: %JsonRemedy.Context.JsonContext{
  current: :root,
  in_string: false,
  position: 0,
  stack: [],
  string_delimiter: nil
}
```

Creates a new empty context with default values.

## Examples

    iex> context = JsonRemedy.Context.JsonContext.new()
    iex> context.current
    :root
    iex> context.stack
    []
    iex> context.position
    0
    iex> context.in_string
    false

# `pop_context`
[🔗](https://github.com/nshkrdotcom/json_remedy/blob/v0.2.1/lib/json_remedy/context/json_context.ex#L90)

```elixir
@spec pop_context(t()) :: t()
```

Pops the most recent context from the stack.

If the stack is empty, the context remains unchanged.

## Examples

    iex> context = %JsonRemedy.Context.JsonContext{current: :object_key, stack: [:root]}
    iex> popped = JsonRemedy.Context.JsonContext.pop_context(context)
    iex> popped.current
    :root
    iex> popped.stack
    []

# `push_context`
[🔗](https://github.com/nshkrdotcom/json_remedy/blob/v0.2.1/lib/json_remedy/context/json_context.ex#L70)

```elixir
@spec push_context(t(), context_value()) :: t()
```

Pushes a new context onto the context stack.

The current context becomes the new context and the previous
current context is pushed onto the stack.

## Examples

    iex> context = JsonRemedy.Context.JsonContext.new()
    iex> new_context = JsonRemedy.Context.JsonContext.push_context(context, :object_key)
    iex> new_context.current
    :object_key
    iex> new_context.stack
    [:root]

# `transition_context`
[🔗](https://github.com/nshkrdotcom/json_remedy/blob/v0.2.1/lib/json_remedy/context/json_context.ex#L164)

```elixir
@spec transition_context(t(), context_value()) :: t()
```

Transitions from the current context to a new context.

Unlike push_context/2, this doesn't modify the stack.

## Examples

    iex> context = %JsonRemedy.Context.JsonContext{current: :object_key}
    iex> transitioned = JsonRemedy.Context.JsonContext.transition_context(context, :object_value)
    iex> transitioned.current
    :object_value

# `update_position`
[🔗](https://github.com/nshkrdotcom/json_remedy/blob/v0.2.1/lib/json_remedy/context/json_context.ex#L146)

```elixir
@spec update_position(t(), non_neg_integer()) :: t()
```

Updates the current position in the input string.

## Examples

    iex> context = JsonRemedy.Context.JsonContext.new()
    iex> updated = JsonRemedy.Context.JsonContext.update_position(context, 15)
    iex> updated.position
    15

---

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