JsonRemedy.Layer4.Validation (json_remedy v0.1.3)

View Source

Layer 4: JSON Validation

This layer attempts to validate and parse clean JSON using Jason. It serves as the final validation layer in the pipeline, confirming that the JSON is valid and ready for consumption.

Key responsibilities:

  • Validate JSON syntax using Jason
  • Parse valid JSON into Elixir terms
  • Apply fast path optimization for valid JSON
  • Handle Jason.DecodeError gracefully
  • Pass malformed JSON to next layer for repair

Summary

Functions

Return a human-readable name for this layer.

Return the priority for this layer. Layer 4 runs fourth in the pipeline.

Process input and validate JSON using Jason.

Check if this layer supports the given input.

Functions

name()

Return a human-readable name for this layer.

priority()

Return the priority for this layer. Layer 4 runs fourth in the pipeline.

process(input, context)

Process input and validate JSON using Jason.

Returns:

  • {:ok, parsed_json, context} - Valid JSON successfully parsed
  • {:continue, input, context} - Invalid JSON, pass to next layer
  • {:error, reason} - Critical error occurred

Examples

iex> JsonRemedy.Layer4.Validation.process("{"name": "Alice"}", %{repairs: [], options: []})
{:ok, %{"name" => "Alice"}, %{repairs: [], options: [], metadata: %{layer4_processed: true}}}

iex> JsonRemedy.Layer4.Validation.process("{name: 'Alice'}", %{repairs: [], options: []})
{:continue, "{name: 'Alice'}", %{repairs: [], options: []}}

supports?(input)

Check if this layer supports the given input.

Layer 4 supports any string input that could potentially be JSON, including malformed JSON that might be repairable.