JsonRemedy.BinaryParser (json_remedy v0.1.0)

View Source

Ultra-fast JSON repair using binary pattern matching.

This module uses Elixir's advanced binary pattern matching to parse and repair JSON without character-by-character iteration. Each function clause matches specific binary patterns, making parsing extremely efficient.

Summary

Functions

Main entry point for binary pattern matching repair.

Types

parse_context()

@type parse_context() :: %{
  repairs: [String.t()],
  position: non_neg_integer(),
  strict: boolean()
}

parse_result()

@type parse_result() :: {term(), binary(), parse_context()}

repair_result()

@type repair_result() ::
  {:ok, term()} | {:ok, term(), [String.t()]} | {:error, String.t()}

Functions

repair(json, opts \\ [])

@spec repair(
  binary(),
  keyword()
) :: repair_result()

Main entry point for binary pattern matching repair.

Examples

iex> JsonRemedy.BinaryParser.repair(~s|{name: "Alice"}|, [])
{:ok, %{"name" => "Alice"}}

iex> JsonRemedy.BinaryParser.repair(~s|[1, 2, 3,]|, logging: true)
{:ok, [1, 2, 3], ["removed trailing comma"]}