JSON Payload Example [C#/.NET Code]

A request payload is data that clients send to the server in the body of an HTTP POST, PUT, or PATCH message that contains important information about the request. To send the JSON with payload to the REST API endpoint, you need to enclose the JSON data in the body of the HTTP request and indicate the data type of the request body with the "Content-Type: application/json" request header. If the client expects a response from the server in JSON format, it also needs to send the "Accept: application/json" header to the server. In this JSON Payload Example, we send JSON to the ReqBin echo URL. Click Send to execute the JSON Payload request online and see the results. The C#/.NET code was automatically generated for the JSON Payload example.
JSON Payload Example [C#/.NET Code] Send
POST /echo/post/json HTTP/1.1
Host: reqbin.com
Accept: application/json
Content-Type: application/json
Content-Length: 52

{
  "Id": 78912,
  "Quantity": 1,
  "Price": 18.00
}
Updated: Viewed: 27555 times
C#/.NET code for JSON Payload example

C#/.NET code for JSON Payload Example

This C#/.NET code snippet was generated automatically for the JSON Payload example.
<< Back to the JSON Payload example

What is JSON?

JavaScript Object Notation (JSON) is a standard text format for storing and transmitting data over a network. API clients use the JSON format extensively to send or receive data from the server. JSON represents four primitive types (strings, numbers, boolean values, and null) and two structured types (objects and arrays). JSON file names use the .json file extension.

What is JSON Payload?

Payload is the essential information in a data block that you send to or receive from the server when making API requests. The Payload can be sent or received in a variety of formats, including JSON. In programming, the payload is used in the context of a message protocol to distinguish between ancillary and actual data in a request. For example, request headers are required by the server to correctly interpret and process the request from a client, but they are not the payload of the request. JSON syntax elements are also not a payload.

JSON Payload Example
POST /echo/post/json HTTP/1.1
Host: reqbin.com
Accept: application/json
Content-Type: application/json
Content-Length: 52

{
  "Id": 12345
}

Where:
  • "id": "12345" - Payload
  • The rest of the information is called service data.

API Payload Formats

There are two types of payloads used:

1. The Payload that the client sends to the server.

Request Payload Format
{
  "Id": 78912,
  "Customer": "Jason Sweet"
}

Where:
  • "Id": 78912 and "Customer": "Jason Sweet" are Payload

2. The Payload returned by the server.

- The OK response Payload format:

OK Payload Example
{
  "success": "true",
  "data": {
    "TotalOrders": 100
  }
}

Where:
  • "success": "true" and "TotalOrders": 100 are Payload

- The FAILED response payload format:

FAILED Payload Example
{
  "success": "false",
  "errorCode": 500,
  "errorDescription": Invalid user ID" 
}

Where:
  • "success": "false", "errorCode": 500 and "errorDescription": Invalid user ID" are Payload

JSON Payload Request Example

Example of sending JSON Payload to ReqBin echo URL:

JSON Payload Request Example
POST /echo/post/json HTTP/1.1
Host: reqbin.com
Accept: application/json
Content-Type: application/json
Content-Length: 52
      
{
  "Id": 78912,
  "Quantity": 1,
  "Price": 18.00
}

JSON Payload Response Example

Example of server response with JSON Payload:

JSON Payload Response Example
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 19
      
{"success":"true"}

See also

Generate code snippets for C#/.NET and other programming languages

Convert your JSON Payload request to the PHP, JavaScript/AJAX, Curl/Bash, Python, Java, C#/.NET code snippets using the C#/.NET code generator.