JsonRemedy.Layer1.ContentCleaning (json_remedy v0.1.3)
View SourceLayer 1: Content Cleaning - Removes non-JSON content and normalizes encoding.
This layer handles:
- Code fence removal (
json ...
) - Comment stripping (// and / /)
- Wrapper text extraction (HTML, prose)
- Encoding normalization
Uses direct string methods instead of regex for better performance and clearer code.
Summary
Functions
Extract JSON from wrapper text (HTML, prose, etc.). Public API version that takes string input directly.
Extract JSON from wrapper text (HTML, prose, etc.).
Return a human-readable name for this layer.
Normalize text encoding to UTF-8. Public API version that takes string input directly.
Normalize text encoding to UTF-8.
Return the priority order for this layer. Layer 1 (Content Cleaning) should run first in the pipeline.
Process input string and apply Layer 1 content cleaning repairs.
Remove code fences from input while preserving fence content in strings.
Strip comments while preserving comment-like content in strings.
Strip comments while preserving comment-like content in strings. Public API version that takes string input directly.
Check if this layer can handle the given input. Layer 1 can handle any text input that may contain JSON with wrapping content.
Validate layer configuration and options. Layer 1 accepts options for enabling/disabling specific cleaning features.
Types
@type layer_result() :: JsonRemedy.LayerBehaviour.layer_result()
@type repair_action() :: JsonRemedy.LayerBehaviour.repair_action()
@type repair_context() :: JsonRemedy.LayerBehaviour.repair_context()
Functions
@spec extract_json_content(input :: String.t()) :: {String.t(), [repair_action()]}
Extract JSON from wrapper text (HTML, prose, etc.). Public API version that takes string input directly.
@spec extract_json_content_internal(input :: {String.t(), [repair_action()]}) :: {String.t(), [repair_action()]}
Extract JSON from wrapper text (HTML, prose, etc.).
@spec name() :: String.t()
Return a human-readable name for this layer.
@spec normalize_encoding(input :: String.t()) :: {String.t(), [repair_action()]}
Normalize text encoding to UTF-8. Public API version that takes string input directly.
@spec normalize_encoding_internal(input :: {String.t(), [repair_action()]}) :: {String.t(), [repair_action()]}
Normalize text encoding to UTF-8.
@spec priority() :: 1
Return the priority order for this layer. Layer 1 (Content Cleaning) should run first in the pipeline.
@spec process(input :: String.t(), context :: repair_context()) :: layer_result()
Process input string and apply Layer 1 content cleaning repairs.
Returns:
{:ok, processed_input, updated_context}
- Layer completed successfully{:continue, input, context}
- Layer doesn't apply, pass to next layer{:error, reason}
- Layer failed, stop pipeline
@spec remove_code_fences(input :: String.t()) :: {String.t(), [repair_action()]}
Remove code fences from input while preserving fence content in strings.
@spec remove_comments(input :: {String.t(), [repair_action()]}) :: {String.t(), [repair_action()]}
Strip comments while preserving comment-like content in strings.
@spec strip_comments(input :: String.t()) :: {String.t(), [repair_action()]}
Strip comments while preserving comment-like content in strings. Public API version that takes string input directly.
Check if this layer can handle the given input. Layer 1 can handle any text input that may contain JSON with wrapping content.
Validate layer configuration and options. Layer 1 accepts options for enabling/disabling specific cleaning features.