Packages
A blazingly fast Elixir library for repairing malformed JSON using binary pattern matching. Handles LLM outputs, legacy data, and broken JSON with intelligent context-aware fixes.
Current section
Files
Jump to
Current section
Files
lib/json_remedy/utils/plain_text_detector.ex
defmodule JsonRemedy.Utils.PlainTextDetector do
@moduledoc false
@spec plain_text?(String.t()) :: boolean()
def plain_text?(input) when is_binary(input) do
trimmed = String.trim(input)
if trimmed == "" do
true
else
not contains_json_structure?(trimmed) and
not json_literal?(trimmed) and
not json_number?(trimmed)
end
end
defp contains_json_structure?(input) do
String.contains?(input, ["{", "}", "[", "]", "\"", ":"])
end
defp json_literal?(input) do
input in ["true", "false", "null"]
end
defp json_number?(input) do
String.match?(input, ~r/^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?$/)
end
end