JSFiddle - React, Tailwind, and code Playground
by velo_ninja
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Base64 JSON Decoder</title>
</head>
<body>
<label for="jsonInput">Enter Base64 JSON Data:</label>
<textarea id="jsonInput" rows="5" cols="50"></textarea>
<button onclick="decodeAndDisplay()">Decode and Display Image</button>
<div>
<h3>Result:</h3>
<div id="result"></div>
</div>
<script>
function decodeAndDisplay() {
// Get JSON data from the input
var base64JsonData = document.getElementById("jsonInput").value.trim();
try {
// Decode Base64
var jsonData = JSON.parse(atob(base64JsonData));
// Display decoded JSON
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = "<p>Decoded JSON:</p><pre>" + JSON.stringify(jsonData, null, 2) + "</pre>";
// Display corresponding image
if (jsonData.image) {
resultDiv.innerHTML += "<p>Corresponding Image:</p><img src='" + jsonData.image + "' alt='Image'>";
}
} catch (error) {
// Handle invalid JSON or Base64 data
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = "<p>Error: Invalid JSON or Base64 data.</p>";
}
}
</script>
</body>
</html>