With ES2017 async/await support, this is how to POST a JSON payload:

(async () => {
  const rawResponse = await fetch('https://httpbin.org/post', {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({a: 1, b: 'Textual content'})
  });
  const content = await rawResponse.json();

  console.log(content);
})();

Can't use ES2017? See @vp_art's answer using promises

The question however is asking for an issue caused by a long since fixed chrome bug.
Original answer follows.

chrome devtools doesn't even show the JSON as part of the request

This is the real issue here, and it's a bug with chrome devtools, fixed in Chrome 46.

That code works fine - it is POSTing the JSON correctly, it just cannot be seen.

I'd expect to see the object I've sent back

that's not working because that is not the correct format for JSfiddle's echo.

The correct code is:

var payload = {
    a: 1,
    b: 2
};

var data = new FormData();
data.append( "json", JSON.stringify( payload ) );

fetch("/echo/json/",
{
    method: "POST",
    body: data
})
.then(function(res){ return res.json(); })
.then(function(data){ alert( JSON.stringify( data ) ) })

For endpoints accepting JSON payloads, the original code is correct

Answer from Razor on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Fetch_API › Using_Fetch
Using the Fetch API - Web APIs | MDN
You can pass an object literal here containing header-name: header-value properties: ... const response = await fetch("https://example.org/post", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ username: "example" }), // …
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-fetch-method
Fetch API in JavaScript with Examples - GeeksforGeeks
October 31, 2025 - response.ok: Checks if the fetch request was successful by ensuring the response status is in the 200-299 range. await response.json(): If the response is successful, it converts the data from the server (usually in JSON format) into a JavaScript ...
🌐
Medium
medium.com › @wisecobbler › using-the-javascript-fetch-api-f92c756340f0
Using the JavaScript Fetch API. At Shopsifter, I use a few different… | by Sophia Shoemaker | Medium
March 10, 2016 - The fetch() method takes two parameters — the URL that you are requesting (or a Request object) and an “options” object. The method returns a Promise object. The Mozilla Developer Network has some great documentation on how Promises work and this article by HTML5 Rocks has some great examples. The basic gist of a Promise object is summed up pretty well on HTML5 Rocks: JavaScript is single threaded, meaning that two bits of script cannot run at the same time, they have to run one after another.
🌐
W3Schools
w3schools.com › jsref › api_fetch.asp
JavaScript Fetch API
The fetch() method returns a Promise that resolves to a Response object. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
Top answer
1 of 16
1293

With ES2017 async/await support, this is how to POST a JSON payload:

(async () => {
  const rawResponse = await fetch('https://httpbin.org/post', {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({a: 1, b: 'Textual content'})
  });
  const content = await rawResponse.json();

  console.log(content);
})();

Can't use ES2017? See @vp_art's answer using promises

The question however is asking for an issue caused by a long since fixed chrome bug.
Original answer follows.

chrome devtools doesn't even show the JSON as part of the request

This is the real issue here, and it's a bug with chrome devtools, fixed in Chrome 46.

That code works fine - it is POSTing the JSON correctly, it just cannot be seen.

I'd expect to see the object I've sent back

that's not working because that is not the correct format for JSfiddle's echo.

The correct code is:

var payload = {
    a: 1,
    b: 2
};

var data = new FormData();
data.append( "json", JSON.stringify( payload ) );

fetch("/echo/json/",
{
    method: "POST",
    body: data
})
.then(function(res){ return res.json(); })
.then(function(data){ alert( JSON.stringify( data ) ) })

For endpoints accepting JSON payloads, the original code is correct

2 of 16
364

I think your issue is jsfiddle can process form-urlencoded request only. But correct way to make json request is pass correct json as a body:

fetch('https://httpbin.org/post', {
  method: 'POST',
  headers: {
    'Accept': 'application/json, text/plain, */*',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({a: 7, str: 'Some string: &=&'})
}).then(res => res.json())
  .then(res => console.log(res));

🌐
Node.js
nodejs.org › learn › getting-started › fetch
Using the Fetch API with Undici in Node.js | Node.js Learn
JavaScriptCopy to clipboard · // Data sent from the client to the server const body = { title: 'foo', body: 'bar', userId: 1, }; async function main() { const response = await fetch('https://jsonplaceholder.typicode.com/posts', { method: 'POST', headers: { 'User-Agent': 'undici-stream-example', 'Content-Type': 'application/json', }, body: JSON.stringify(body), }); const data = await response.json(); console.log(data); // returns something like: // { title: 'foo', body: 'bar', userId: 1, id: 101 } } main().catch(console.error); JavaScriptCopy to clipboard ·
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › fetch
Window: fetch() method - Web APIs | MDN
In our Fetch Request with init example (see Fetch Request init live) we do the same thing except that we pass in an options object when we invoke fetch().
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › javascript-fetch-api-for-beginners
JavaScript Fetch API For Beginners – Explained With Code Examples
February 23, 2024 - After processing the response into a data object, JavaScript will change the text of the <h1> and <h2> elements above to reflect the name and email of the user. If you run the code above, you'll get the following output: ... And that's how you send a GET request using Fetch and display the returned data in HTML. Note that depending on the request you are asking for, an API might return a different type of data. In this example, the typicode API sends back an object, but you might also get an array when you request more than one unit of data.
🌐
Oxylabs
oxylabs.io › blog › nodejs-fetch-api
How to Make HTTP Requests in Node.js With Fetch API
Since then, you can write your server-side JavaScript code that uses the Fetch API without installing a third-party library. To check your Node.js version, run the following command in your terminal: ... If you’re running a Node.js version between 17.5 and 18, you can run Fetch API code files by enabling the --experimental-fetch flag: ... For the following examples, a scraping sandbox website will be used as a target.
🌐
DEV Community
dev.to › tienbku › javascript-fetch-getpostputdelete-example-3dmp
Javascript Fetch example: Get/Post/Put/Delete - DEV Community
October 23, 2021 - JavaScript Fetch API provides an interface for accessing and manipulating HTTP requests and responses. In this tutorial, we will create examples that use Javascript fetch() method to make Get/Post/Put/Delete request.
🌐
JavaScript in Plain English
javascript.plainenglish.io › async-await-the-easy-way-to-fetch-e490efd2e298
Async/Await: The Easy Way to Fetch | by Brian Rhodes | JavaScript in Plain English
September 23, 2024 - 💡 Also, explore some of the most exciting additions to JavaScript in ES15: ... I think it is best to explain promises in a practical sense rather than doing what most tutorials will do: Here we have a function that is supposed to “load images” by fetching them from a URL assigned to a variable (IMG_URL).
🌐
Twelve Data
twelvedata.com › docs
API Documentation - Twelve Data
Example: United States · format string · The format of the response data · Supports: JSON, CSV · Default: JSON · delimiter string · The separator used in the CSV response data · Default: ; show_plan boolean · Adds info on which plan symbol is available · Default: false · include_delisted boolean · Include delisted identifiers · Default: false · page integer · Page number of the results to fetch ·
🌐
Learn JavaScript
learnjavascript.online › topics › fetch.html
JavaScript Fetch API use cases for fetching data, JSON, XML, etc. | Learn JavaScript
Access-Control-Allow-Origin: https://example.com Access-Control-Allow-Methods: GET, POST, PUT, DELETE Access-Control-Allow-Headers: Content-Type Access-Control-Max-Age: 86400 · Working with the fetch API should be relatively easy if you're comfortable with promises.
🌐
Mimo
mimo.org › glossary › javascript › fetch-api
JavaScript Fetch API: Syntax, Usage, and Examples
The JavaScript Fetch API makes HTTP requests simple and efficient. Use fetch() with promises or async/await to retrieve, send, and manage data seamlessly.
🌐
DevGenius
blog.devgenius.io › how-to-use-fetch-in-javascript-for-beginners-6937dd094e4a
How to use fetch() in Javascript for beginners | by Jose Escobedo | Dev Genius
March 4, 2022 - By default the fetch() function uses the GET method but there are other ways in which we can use fetch. In this example, in the first then() we create an anonymous function using arrow notation and we pass in “res” as arguments.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-use-the-javascript-fetch-api-to-get-data
How To Use JavaScript Fetch API To Get Data? - GeeksforGeeks
October 31, 2025 - Error handling in the Fetch API ensures that issues like network failures or invalid responses are properly managed. Here's a simple example to demonstrate how to handle errors with Fetch.
🌐
Chip Cullen
chipcullen.com › how-to-post-data-with-fetch-api
How to POST *Data* with the Fetch API: Chip Cullen
To do that, the trick was using ... string. You add to it with the .append method that it has. ... let example = new URLSearchParams(); example.append(`myKey`, `my value`); console.log(example); // ?myKey=my ...
🌐
GeeksforGeeks
geeksforgeeks.org › computer networks › get-and-post-method-using-fetch-api
Get and Post method using Fetch API - GeeksforGeeks
September 24, 2024 - A POST request is used to send data to the server, commonly for submitting forms or adding new data. In this example, we'll send a POST request to add a new post to the posts endpoint of the JSONPlaceholder API.
🌐
Bennadel
bennadel.com › blog › 4179-building-an-api-client-with-the-fetch-api-in-javascript.htm
Building An API Client With The fetch() API In JavaScript
January 9, 2022 - Ben Nadel explores the fetch() API for the first time; and uses it to build an opinionated, application-specific API client in JavaScript.
🌐
Axios
axios-http.com › docs › intro
First steps | axios | Promise based HTTP client
An axios request can be made in as few as two lines of code. Making your first request with axios is very simple. You can make a request to any API by providing the URL and method. For example, to make a GET request to the JSONPlaceholder API, you can use the following code: