JsonRemedy.Utils.MultipleJsonDetector (JsonRemedy v0.1.11)

View Source

Utility for detecting and parsing multiple consecutive JSON values.

Handles Pattern 1 from json_repair Python library: Multiple complete JSON values like []{}[[], {}]

This must run BEFORE the layer pipeline because:

  • Layer 1 might remove trailing JSON as "wrapper text"
  • Layer 3 adds commas between ]{ which breaks parsing

Based on json_repair Python library (json_parser.py:78-99)

Summary

Functions

Parse JSON string that may contain multiple consecutive values. Returns {:ok, parsed_value} or {:error, reason}

Parse first complete JSON value and return remaining string. Returns {:ok, parsed, remaining} or {:error, reason}

Functions

parse_multiple(json_string)

@spec parse_multiple(String.t()) :: {:ok, term()} | {:error, String.t()}

Parse JSON string that may contain multiple consecutive values. Returns {:ok, parsed_value} or {:error, reason}

If multiple values found, returns them in an array. If single value found, returns it unwrapped.

parse_with_position(json_string)

@spec parse_with_position(String.t()) ::
  {:ok, term(), String.t()} | {:error, String.t()}

Parse first complete JSON value and return remaining string. Returns {:ok, parsed, remaining} or {:error, reason}