I need to send via REST (not including some other sensitive information):
{"@Scope": "Local"}
In the class file I JsonProperty for Json.Net serialization:
[JsonProperty("@Scope")]
public string Scope { get; set; }
When putting together the json message to be sent via WebRequest, I have
{@Scope = "Local"}
But after running:
string jsonString = System.Text.Json.JsonSerializer.Serialize(message);
The message being sent out is
{"Scope": "Local"}
For some reason I though System.Text.Json will pick up JsonProperty attributes but apparently there should be some other way.
[JsonPropertyName("@Scope")]? e.g see stackoverflow.com/a/58299628/15410@is not a valid character in C# identifiers itself; it's used as an escape sequence to allow keywords to serve as identifiers. So writing@Scopehas the same meaning as just writingScope; you need to use whatever you'd normally use to override serialization to get such names as literals.JsonPropertyNameattribute"