Ferramenta de Entrada Inteligente
Auto-detecte JSON, Base64, JWT ou URL e roteie para saída decodificada/formatada
What is Automatic Format Detection?
Automatic format detection is the process of identifying the data format of an arbitrary text input without requiring the user to specify it explicitly. When you paste a string into the Smart Input Tool, it analyzes structural patterns, character distributions, and format-specific signatures to determine whether the input is JSON, Base64, a JWT token, a URL, XML, YAML, CSV, a UUID, a cron expression, SQL, or one of many other recognized formats. Once identified, the tool routes the input to the appropriate processor — formatting, decoding, validating, or parsing it automatically. This eliminates the manual step of choosing the right tool and accelerates debugging workflows where you frequently switch between different data representations.
Format Fingerprints and Structural Signatures
Each data format has a unique structural fingerprint — a combination of characters, delimiters, and patterns that distinguish it from other formats. The detection engine uses these fingerprints as the first pass in identification:
- JSON: Starts with
{or[, contains quoted keys separated by colons, uses commas as delimiters between values. Nested braces and brackets indicate object/array depth. - JWT: Three Base64URL-encoded segments separated by exactly two dots (
xxxxx.yyyyy.zzzzz). The header segment decodes to JSON containing"alg"and"typ":"JWT"fields. - Base64: Contains only characters from the alphabet
A-Za-z0-9+/with optional=padding at the end. Length is a multiple of 4 when padded. No whitespace or special characters outside the alphabet. - URL: Starts with a scheme (
http://,https://,ftp://) followed by a domain with at least one dot, optional path segments, query parameters, and fragment identifiers. - XML: Begins with
<?xmldeclaration or an opening tag<tagname. Contains matching opening and closing tags with attributes in quotes. - YAML: Uses indentation-based structure with
key: valuepairs. May start with---document separator. No braces or brackets at the top level (distinguishes from JSON). - UUID: Exactly 36 characters matching the pattern
8-4-4-4-12hexadecimal groups separated by hyphens (e.g.,550e8400-e29b-41d4-a716-446655440000). - Cron expression: Five or six space-separated fields containing numbers, asterisks, slashes, commas, and hyphens representing minute, hour, day-of-month, month, and day-of-week.
- SQL: Starts with SQL keywords like
SELECT,INSERT,UPDATE,DELETE,CREATE, orALTERfollowed by standard SQL syntax. - CSV: Multiple lines with consistent comma (or semicolon/tab) delimiters, optional quoted fields, and a consistent column count across rows.
These fingerprints overlap in some cases — for example, a short Base64 string might look like a word, or a JSON object might also be valid YAML. The detection engine resolves ambiguity through confidence scoring rather than a simple first-match approach.
Confidence Scoring and Disambiguation
When an input matches multiple format fingerprints, the detection engine assigns a confidence score (0.0 to 1.0) to each candidate format. The format with the highest score is selected as the primary detection result. Confidence scoring considers several factors:
- Structural completeness: Does the input fully conform to the format grammar, or only partially? A complete JSON parse without errors yields a higher score than a string that merely starts with
{. - Character distribution: Base64 strings have a uniform distribution across the 64-character alphabet. Natural language text has a very different distribution (vowels, common letters). Statistical analysis helps distinguish encoded data from plain text.
- Length heuristics: A 36-character string matching the UUID regex gets a near-perfect confidence score. A 4-character string matching Base64 patterns gets a low score because it could easily be a coincidental match.
- Contextual markers: JWT tokens always decode to JSON with specific fields (
alg,typ,iat,exp). The presence of these fields after decoding the header dramatically increases confidence. - Format exclusivity: Some patterns are highly exclusive — the UUID hyphen pattern is unlikely to appear in other formats. Others like "starts with a letter" are shared across many formats and contribute less to confidence.
The final detection result includes the top candidate with its confidence score, plus alternative candidates ranked by score. If the primary detection has a confidence below 0.6, the tool flags the result as uncertain and presents multiple options to the user, allowing manual selection of the intended format.
Pattern Matching Techniques
The detection engine combines multiple pattern matching strategies operating in sequence, each adding evidence to the scoring system:
Regex signatures form the first detection layer. Each format has one or more
regular expressions that match its structural pattern. For example, UUIDs use
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-7][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
which also validates the version nibble and variant bits. JWT uses
/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/ to match the three-segment
dot-separated structure.
Parser validation provides the highest confidence. After a regex matches, the
engine attempts to actually parse the input using the format's parser. JSON.parse()
for JSON, atob() for Base64, new URL() for URLs. A successful parse
with no thrown exceptions confirms the format beyond any regex match. A parse failure demotes
the candidate's confidence even if the regex matched.
Magic characters and prefixes provide quick-reject capabilities. If the first
non-whitespace character is { or [, the input is almost certainly JSON
(or possibly a JSON-like subset of YAML). If it starts with <, XML or HTML is
likely. These prefix checks run in constant time and eliminate most candidates before expensive
parsing begins.
Statistical analysis handles ambiguous cases. When regex and prefix checks are inconclusive, the engine analyzes character frequency, entropy, and line structure. High entropy with uniform character distribution suggests encoded data (Base64, hex). Low entropy with natural word boundaries suggests plain text or markup.
Practical Workflow and Routing
The Smart Input Tool integrates into a developer's debugging workflow as a universal entry point. Instead of manually choosing between the JSON formatter, Base64 decoder, JWT decoder, or URL parser, you paste any unknown payload and let the tool decide. The typical workflow is:
- Copy a value from a log file, API response, environment variable, or clipboard.
- Paste it into the Smart Input Tool's text area.
- The tool instantly identifies the format and displays the detection result with confidence.
- The detected format is processed automatically — JSON is formatted, Base64 is decoded, JWTs are split into header/payload/signature, URLs are parsed into components.
- If the detection is incorrect, select the correct format from the alternatives list to re-process.
This approach saves significant time when debugging systems that pass data through multiple encoding layers. A common scenario: an API returns a Base64-encoded JWT inside a JSON response. You can paste the full response, the tool detects JSON and formats it; then you copy the token field, paste it again, and the tool detects Base64; decode reveals the JWT, paste once more, and header/payload are extracted. Each step requires zero tool selection — just paste and read.
Code Examples
Format detection engine with confidence scoring
interface DetectionResult {
format: string;
confidence: number;
alternatives: { format: string; confidence: number }[];
}
function detectFormat(input: string): DetectionResult {
const trimmed = input.trim();
const candidates: { format: string; confidence: number }[] = [];
// UUID detection (very high specificity)
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-7][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
if (uuidRegex.test(trimmed)) {
candidates.push({ format: 'uuid', confidence: 0.99 });
}
// JWT detection (three dot-separated Base64URL segments)
const jwtRegex = /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/;
if (jwtRegex.test(trimmed) && trimmed.split('.').length === 3) {
try {
const header = JSON.parse(atob(trimmed.split('.')[0].replace(/-/g, '+').replace(/_/g, '/')));
if (header.alg) candidates.push({ format: 'jwt', confidence: 0.95 });
} catch {
candidates.push({ format: 'jwt', confidence: 0.4 });
}
}
// JSON detection (parse validation)
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
try {
JSON.parse(trimmed);
candidates.push({ format: 'json', confidence: 0.95 });
} catch {
candidates.push({ format: 'json', confidence: 0.3 });
}
}
// URL detection
try {
const url = new URL(trimmed);
if (url.protocol === 'http:' || url.protocol === 'https:') {
candidates.push({ format: 'url', confidence: 0.9 });
}
} catch { /* not a URL */ }
// Base64 detection (alphabet + length check)
const base64Regex = /^[A-Za-z0-9+/]+=*$/;
if (base64Regex.test(trimmed) && trimmed.length >= 8 && trimmed.length % 4 === 0) {
try {
atob(trimmed);
candidates.push({ format: 'base64', confidence: 0.7 });
} catch {
candidates.push({ format: 'base64', confidence: 0.2 });
}
}
// Sort by confidence descending
candidates.sort((a, b) => b.confidence - a.confidence);
const primary = candidates[0] || { format: 'unknown', confidence: 0 };
return {
format: primary.format,
confidence: primary.confidence,
alternatives: candidates.slice(1),
};
}
// Usage
const result = detectFormat('eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.rK1p5');
// → { format: "jwt", confidence: 0.95, alternatives: [...] }