JSFiddle - React, Tailwind, and code Playground

by Haze32

HTML

<textarea id="output" rows="10" cols="50"></textarea>
<button onclick="loadJSON()">Load JSON</button>

JavaScript

function loadJSON() {
    // Using a publicly available JSON file from GitHub
    const url = 'https://jsonplaceholder.typicode.com/users';
    
    fetch(url)
        .then(response => response.json())
        .then(data => {
            // Format the JSON with indentation
            const formattedJson = JSON.stringify(data, null, 2);
            document.getElementById('output').value = formattedJson;
        })
        .catch(error => {
            document.getElementById('output').value = 'Error loading JSON: ' + error;
        });
}