{"id":48252,"library":"json-fetch","title":"JSON Fetch","description":"json-fetch is a lightweight wrapper around the ES6 fetch API that simplifies interacting with JSON APIs. It automatically serializes request bodies to JSON and sets appropriate Content-Type headers, parses responses as JSON when Content-Type is application/json, includes credentials by default, and supports configurable retry logic via the promise-retry library. Current stable version: 9.0.10. Release cadence is irregular. Key differentiators: built-in retry strategies for 5xx errors and network errors, request/response lifecycle callbacks, TypeScript type declarations (requires DOM lib), and a simple API that reduces boilerplate for JSON API calls. Supports Node.js >=12.","status":"active","version":"9.0.10","language":"javascript","source_language":"en","source_url":"git://github.com/goodeggs/json-fetch","tags":["javascript","fetch","api","json","es6"],"install":[{"cmd":"npm install json-fetch","lang":"bash","label":"npm"},{"cmd":"yarn add json-fetch","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-fetch","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"used for configurable retry behavior when shouldRetry option is provided","package":"promise-retry","optional":true}],"imports":[{"note":"Package is ESM-only since v7. CommonJS require() will not work with default export.","wrong":"const jsonFetch = require('json-fetch')","symbol":"default","correct":"import jsonFetch from 'json-fetch'"},{"note":"retriers is a named export. CommonJS require('json-fetch').retriers is also valid but not tree-shakable.","wrong":"const retriers = require('json-fetch').retriers","symbol":"retriers","correct":"import { retriers } from 'json-fetch'"},{"note":"This is a named export, not default. Available since v6.","wrong":"import FetchUnexpectedStatusError from 'json-fetch'","symbol":"FetchUnexpectedStatusError","correct":"import { FetchUnexpectedStatusError } from 'json-fetch'"},{"note":"TypeScript users should import the type for response shape. Not a runtime export.","wrong":"","symbol":"FetchResponse","correct":"import type { FetchResponse } from 'json-fetch'"}],"quickstart":{"code":"import jsonFetch, { retriers } from 'json-fetch';\n\nasync function main() {\n  try {\n    const response = await jsonFetch('https://api.example.com/data', {\n      method: 'POST',\n      body: { key: 'value' },\n      expectedStatuses: [200],\n      shouldRetry: retriers.isNetworkError,\n      retry: { retries: 3 },\n      onRequestStart: (url, options) => console.log('Request started', url),\n      onRequestEnd: (url, options, response) => console.log('Request ended', url, response.status),\n    });\n    console.log('Response body:', response.body);\n  } catch (err) {\n    if (err.name === 'FetchUnexpectedStatusError') {\n      console.error('Unexpected status:', err.response.status, err.response.body);\n    } else {\n      console.error('Network or other error:', err);\n    }\n  }\n}\n\nmain();","lang":"typescript","description":"Shows basic POST request with JSON body, expected status validation, retry on network errors, and request lifecycle callbacks."},"warnings":[{"fix":"Import as default function directly: `import jsonFetch from 'json-fetch'`.","message":"Default export changed from an object to a function in v7. Previously required `jsonFetch.default()` call.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Upgrade Node.js to v12 or later.","message":"Node.js >=12 required. Older versions will cause import/syntax errors.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Add `\"lib\": [\"DOM\", \"ES2020\"]` to tsconfig.json.","message":"TypeScript type declarations only work if DOM lib is included in tsconfig. Otherwise type errors for RequestInit etc.","severity":"gotcha","affected_versions":">=8.0.0"},{"fix":"Keep using as-is; no immediate action needed.","message":"Options `retry` and `shouldRetry` are deprecated in favor of `retry` and `shouldRetry` passed directly (no change in name, but the shape may change in future). Current usage is still supported.","severity":"deprecated","affected_versions":">=9.0.0"},{"fix":"Ensure your API returns Content-Type: application/json or handle manually.","message":"The library does not handle non-JSON responses gracefully. If Content-Type is not application/json, response.body will be undefined.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'12':103 '5xx':76 '9.0.10':63 'api':14,20,93,99,106 'application/json':44 'appropri':30 'around':10 'automat':22 'bodi':25 'boilerpl':96 'built':71 'built-in':70 'cadenc':65 'call':100 'callback':83 'configur':51 'content':32,41 'content-typ':31,40 'credenti':46 'current':60 'declar':86 'default':48 'differenti':69 'dom':88 'error':77,80 'es6':12,108 'fetch':2,5,13,105 'header':34 'includ':45 'interact':17 'irregular':67 'javascript':104 'json':1,4,19,27,38,98,107 'json-fetch':3 'key':68 'lib':89 'librari':59 'lifecycl':82 'lightweight':8 'logic':53 'network':79 'node.js':102 'pars':35 'promis':57 'promise-retri':56 'reduc':95 'releas':64 'request':24 'request/response':81 'requir':87 'respons':36 'retri':52,58,73 'serial':23 'set':29 'simpl':92 'simplifi':16 'stabl':61 'strategi':74 'support':50,101 'type':33,42,85 'typescript':84 'version':62 'via':54 'wrapper':9","created_at":"2026-06-07T16:55:40.597997+00:00","updated_at":"2026-06-07T16:55:40.597997+00:00","problems":[{"fix":"Run `npm install json-fetch` or `yarn add json-fetch`. Ensure no path typo.","cause":"Package not installed or mismatched import path.","error":"Cannot find module 'json-fetch'"},{"fix":"Use `import jsonFetch from 'json-fetch'` or switch to dynamic import.","cause":"Using CommonJS require() on ESM-only module.","error":"TypeError: jsonFetch is not a function"},{"fix":"Use `import jsonFetch from 'json-fetch'` directly.","cause":"Importing the old default export as an object (jsonFetch.default).","error":"Property 'default' does not exist on type '...'"},{"fix":"Use `import { retriers } from 'json-fetch'`.","cause":"Trying to access retriers as a property of the default import instead of named import.","error":"error TS2339: Property 'retriers' does not exist on type '...'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/goodeggs/json-fetch","github":"git://github.com/goodeggs/json-fetch","docs":null,"changelog":null,"pypi":null,"npm":"json-fetch","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}