<?php
// powered by knuepower.de
$result = '';
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $input = $_POST['json_input'] ?? '';
    json_decode($input);
    if (json_last_error() === JSON_ERROR_NONE) {
        $result = json_encode(json_decode($input), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
    } else {
        $error = json_last_error_msg();
    }
}
?>
<form method="post">
  <textarea name="json_input" rows="6" cols="60" placeholder="JSON eingeben" required><?= htmlspecialchars($_POST['json_input'] ?? '') ?></textarea><br>
  <button type="submit">Validieren & Formatieren</button>
</form>
<?php if ($result): ?>
<p><strong>Formatiertes JSON:</strong></p>
<pre><?= htmlspecialchars($result) ?></pre>
<?php elseif ($error): ?>
<p style="color:red;"><strong>Fehler:</strong> <?= htmlspecialchars($error) ?></p>
<?php endif; ?>
