# `Replicant.Casting.ArrayParser`
[🔗](https://github.com/baselabs/replicant/blob/v0.3.1/lib/replicant/casting/array_parser.ex#L1)

Parser for PostgreSQL array literals

Implementation inspired by Supabase Realtime and Sequin

# `parse`

Parses a PostgreSQL array literal string into an Elixir list.

Returns all elements as strings - the caller is responsible for any
type conversion. NULL values are returned as `nil`.

## Parameters
  - `array_string` - PostgreSQL array literal (e.g., `"{1,2,3}"`)

## Returns
  - `{:ok, list}` - Successfully parsed array as nested list
  - `{:error, reason}` - Parsing failed with reason

## Examples

    # Simple arrays
    Replicant.Casting.ArrayParser.parse("{1,2,3}")
    {:ok, ["1", "2", "3"]}

    # Empty arrays
    Replicant.Casting.ArrayParser.parse("{}")
    {:ok, []}

    # Arrays with quoted strings
    Replicant.Casting.ArrayParser.parse("{"hello, world","foo"}")
    {:ok, ["hello, world", "foo"]}

    # Nested arrays
    Replicant.Casting.ArrayParser.parse("{{1,2},{3,4}}")
    {:ok, [["1", "2"], ["3", "4"]]}

    # NULL values
    Replicant.Casting.ArrayParser.parse("{1,NULL,3}")
    {:ok, ["1", nil, "3"]}

---

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