New paste Use cases Explore public pastes Text tools Developer API The Paste Library Security Sign in with Google
JAVASCRIPTExample pasteCreated 2026-08-032 viewsNo expiry

Fetch JSON with a timeout

Raw New paste
javascriptRead-only
1
async function fetchJson(url, timeoutMs = 5000) {
  const controller = new AbortController();
  const timeout = setTimeout(() => controller.abort(), timeoutMs);
  try {
    const response = await fetch(url, { signal: controller.signal });
    if (!response.ok) throw new Error(`HTTP ${response.status}`);
    return await response.json();
  } finally {
    clearTimeout(timeout);
  }
}
Report abuse

Paste details

Visibility
Public
Size
385 bytes
Protection
Standard link access
Retention
No automatic expiry

Share with confidence

Unlisted links are not searchable, but anyone with the URL can open them. Never paste live credentials or personal data.