{"id":49359,"library":"simple-json-fetch","title":"simple-json-fetch","description":"A lightweight wrapper around the WHATWG fetch() API that automatically parses JSON responses and resolves only for successful HTTP status codes (200-299) with valid JSON. Version 1.0.1 is the latest and only stable version. It has zero runtime dependencies but expects a fetch polyfill in environments without native fetch. Unlike raw fetch, it simplifies JSON handling by providing a resolved `.json` property on success and an `.error` property on rejection. Suitable for projects where you want concise JSON fetching without manual response parsing.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/MoOx/simple-json-fetch","tags":["javascript","whatwg","fetch","json"],"install":[{"cmd":"npm install simple-json-fetch","lang":"bash","label":"npm"},{"cmd":"yarn add simple-json-fetch","lang":"bash","label":"yarn"},{"cmd":"pnpm add simple-json-fetch","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is ESM-only. It uses default export.","wrong":"const jsonFetch = require('simple-json-fetch')","symbol":"jsonFetch","correct":"import jsonFetch from 'simple-json-fetch'"},{"note":"The package exports a default function, not a named export.","wrong":"import { jsonFetch } from 'simple-json-fetch'","symbol":"default export","correct":"import jsonFetch from 'simple-json-fetch'"},{"note":"The polyfill must be imported as a side-effect before using jsonFetch.","wrong":"import fetch from 'whatwg-fetch'","symbol":"fetch polyfill","correct":"import 'whatwg-fetch'"}],"quickstart":{"code":"import 'whatwg-fetch'\nimport jsonFetch from 'simple-json-fetch'\n\nconst url = 'https://api.example.com/data'\nconst options = { method: 'GET', headers: { 'Accept': 'application/json' } }\n\njsonFetch(url, options)\n  .then(response => {\n    console.log('Success:', response.json)\n    // response.json is the parsed JavaScript object\n  })\n  .catch(response => {\n    console.error('Error:', response.error)\n    // response.error is the error (e.g., parse error)\n    console.log('Status:', response.status, response.statusText)\n  })","lang":"javascript","description":"Demonstrates importing the polyfill and jsonFetch, making a GET request, and handling success/failure with automatic JSON parsing."},"warnings":[{"fix":"npm install whatwg-fetch and add import 'whatwg-fetch' at the top of your entry file.","message":"Requires a fetch polyfill in environments without native fetch (e.g., older Node, some browsers). Install whatwg-fetch or similar and import it before jsonFetch.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Always handle rejection, and check response.status for additional context.","message":"The promise resolves only if HTTP status is 200-299 AND the response body is valid JSON. Any other status or malformed JSON causes rejection.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Consider adding tests or use a well-tested alternative like ky or got.","message":"No automated tests; the package is a personal snippet. Use with caution in production.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'-299':27 '1.0.1':32 '200':26 'api':12 'around':8 'automat':14 'code':25 'concis':82 'depend':44 'environ':51 'error':72 'expect':46 'fetch':4,11,48,54,57,84,91 'handl':61 'http':23 'javascript':89 'json':3,16,30,60,66,83,92 'latest':35 'lightweight':6 'manual':86 'nativ':53 'pars':15,88 'polyfil':49 'project':78 'properti':67,73 'provid':63 'raw':56 'reject':75 'resolv':19,65 'respons':17,87 'runtim':43 'simpl':2 'simple-json-fetch':1 'simplifi':59 'stabl':38 'status':24 'success':22,69 'suitabl':76 'unlik':55 'valid':29 'version':31,39 'want':81 'whatwg':10,90 'without':52,85 'wrapper':7 'zero':42","created_at":"2026-06-07T17:01:21.720469+00:00","updated_at":"2026-06-07T17:01:21.720469+00:00","problems":[{"fix":"Install whatwg-fetch (npm install whatwg-fetch) and add import 'whatwg-fetch' before using simple-json-fetch.","cause":"Missing fetch polyfill in an environment without native fetch (e.g., Node.js <18).","error":"Uncaught TypeError: fetch is not a function"},{"fix":"Use import jsonFetch from 'simple-json-fetch' (without curly braces).","cause":"Using named import instead of default import.","error":"Uncaught SyntaxError: The requested module 'simple-json-fetch' does not provide an export named 'jsonFetch'"},{"fix":"Change to import jsonFetch from 'simple-json-fetch' or use dynamic import().","cause":"Using require() on an ESM-only package.","error":"Error: jsonFetch is not a function"}],"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/MoOx/simple-json-fetch#readme","github":"https://github.com/MoOx/simple-json-fetch","docs":null,"changelog":null,"pypi":null,"npm":"simple-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}}