I want to pass a null value to a key using a POST request in an API.
For example, I want to pass the below JSON data. That is, Exp and TeamID is null.
{
"ID":162617,
"TextKey":"107737",
"Exp":null,
"TeamID":null
}
The result is accepted in Postman, but when I tried passing the same using C# code below, my JSON content becomes invalid.
long idvalue = 162617;
string textkeyvalue = "107737";
string expvalue = null;
long? teamIDvalue = null;
string postData = "{\"ID\":" + idvalue + ",\"TextKey\":\"" + textkeyvalue + "\",\"Exp\":\"" + expvalue + "\",\"TeamID\":\"" + teamIDvalue + "\"}";
Which gives me the following output.
{
"ID":162617,
"TextKey":"107737",
"Exp":"",
"TeamID":
}
And my request fails due to the invalid JSON body. So how do i pass this sort of null data or null keyword?
Note : All the Key value pairs are mandatory in my API, so I cannot omit them if they are null.
I just want to pass the data in the below format.
{
"ID":162617,
"TextKey":"107737",
"Exp":null,
"TeamID":null
}