fetch-json (v3.5.2) is a lightweight JavaScript library (under 4 KB minified) that wraps the Fetch API to reduce boilerplate for JSON REST calls. It automatically sets the content-type header to application/json, runs .json() on responses, serializes request bodies with JSON.stringify(), appends query parameters for GET requests, sets credentials to same-origin, and converts non-JSON text responses to JSON. Released regularly, it supports both browser and Node.js environments, ships TypeScript type definitions, and is ideal for JAMstack architectures. Compared to raw fetch or axios, it provides a simpler API with sensible defaults for JSON endpoints, especially for serverless and client-side apps.
npm install fetch-jsonNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates a basic GET request with query parameters using fetchJson.get().
Use import { fetchJson } from 'fetch-json'; instead of require().Check data.error in the then() callback or use try/catch with async/await.
Pass an options object with credentials: 'include' as third argument to fetchJson.get/post.
Wrap call in try/catch or use the error handler in then().
Change 'import fetchJson from "fetch-json"' to 'import { fetchJson } from "fetch-json"'.Use import { fetchJson } from 'fetch-json'; or upgrade to Node.js with ESM support.Check the URL or handle the error with try/catch and inspect response status.
No dependency data recorded yet.