JsonRemedy.Utils.MultipleJsonDetector (JsonRemedy v0.2.1)

Copy Markdown 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, multiple?} or {:error, reason}

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

Functions

parse_multiple(json_string, options \\ [])

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

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

If multiple values found, returns them in an array with multiple?=true. If single value found, returns it unwrapped with multiple?=false.

Special case: Object continuation patterns like {"a":1},"b":2} should return multiple?=false to let ObjectMerger handle them.

parse_with_position(json_string, options)

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

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