Switch to Bing in English
Open links in new tab
    • Work Report
    • Email
    • Rewrite
    • Speech
    • Title Generator
    • Smart Reply
    • Poem
    • Essay
    • Joke
    • Instagram Post
    • X Post
    • Facebook Post
    • Story
    • Cover Letter
    • Resume
    • Job Description
    • Recommendation Letter
    • Resignation Letter
    • Invitation Letter
    • Greeting Message
    • Try more templates
  1. To send a JSON HTTP request in JavaScript, you can use the XMLHttpRequest object or the fetch API. Below is an example using the fetch API to send a JSON object and include the current date in the filename.

    Example using Fetch API

    const data = {
    name: "John Doe",
    age: 30
    };

    const date = new Date().toISOString().split('T')[0]; // Get current date in YYYY-MM-DD format
    const filename = `data_${date}.json`;

    fetch('https://example.com/api', {
    method: 'POST',
    headers: {
    'Content-Type': 'application/json'
    },
    body: JSON.stringify(data)
    })
    then(response => response.json())
    then(data => {
    console.log('Success:', data);
    })
    catch((error) => {
    console.error('Error:', error);
    });
    Copied!

    Example using XMLHttpRequest

    const xhr = new XMLHttpRequest();
    const url = 'https://example.com/api';
    const data = JSON.stringify({
    name: "John Doe",
    age: 30
    });

    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-Type", "application/json");

    xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && xhr.status === 200) {
    const jsonResponse = JSON.parse(xhr.responseText);
    console.log(jsonResponse);
    }
    };

    xhr.send(data);
    Copied!
    Feedback
  2. Request: json () method - Web APIs | MDN

    The json() method of the Request interface reads the request body and returns it as a promise that resolves with the result of parsing the body text as JSON.
    Syntax

    Parameters Return value
    A Promise that resolves to a JavaScript object. This object could be anything that can be represented by JSON — an object, an array, a string, a number…

    Browser compatibility

    BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

  3. JSON XMLHttpRequest - W3Schools

    A common use of JSON is to read data from a web server, and display the data in a web page. This chapter will teach you, in 4 easy steps, how to read JSON data, using XMLHttp.

  4. 「サンプル付き」APIレスポンスでJSONデータを使用 …

    Jul 23, 2025 · APIを設計するときに、そのレスポンスでは、JSONデータを使うのは一番多くなります。 本文では、さまざまな基本知識を解説した上、どのよ …

  5. JSON:API — Examples

    If the server cannot parse the request as valid JSON, including source doesn’t make sense (because there’s no JSON document for source to refer to). Here’s how the server might respond to an invalid …

  6. Is there any standard for JSON API response format?

    I was really interested by this question as I had to design a JSON API recently and found myself wondering if they were any standards defining a response format.

    • Reviews: 16
    • People also ask
    • JSON requests and responses - Atlassian

      Dec 8, 2017 · To make a request with JSON, the appropriate HTTP headers are: As an example, the following command attempts to authenticate a user by password with a JSON request: If this is the …

    • JSON and Restful APIs

      JSON's lightweight nature, readability, and compatibility with various programming languages make it the go-to choice for APIs. In this article, we’ll explore how to use JSON in RESTful APIs, covering best …

    • How to use JSON to do an HTTP Request - Quackit Tutorials

      Below is a sample HTML page that retrieves that JSON data via HTTP, and uses JavaScript to wrap it in HTML tags and output it to the HTML document. I've provided plenty of comments in order to explain …

    • What is the correct JSON Response Format? - ReqBin

      Dec 23, 2022 · For the server to respond in JSON format, include the JSON data in the response message body and specify the "Content-Type: application/json" HTTP header. The server may also set …

    By using this site you agree to the use of cookies for analytics, personalized content, and ads.Learn more about third party cookies|Microsoft Privacy Policy