I’m trying to implement the same functionality in UiPath Studio using the HTTP Request activity. However, I’m running into an error when assigning a value to the ContentJsonSchema (Body). I suspect it might be related to string escaping, but I’m not entirely sure.
To represent a backslash, you need to double it. For example, \ (one backslash) is interpreted as a special character (like a new line or a tab), while \\\\ (two backslashes) represents a literal backslash in the string.
Examples:
“C:\\Users” would be interpreted as “C:\Users”.
“This is a test \"test\"” would be interpreted as “This is a test "test"”.
ooof guys, doing it this way leads to so many errors, as shown in this thread with character escapes and missing symbols when built manually.
Its so much easier than this now, just ask a GPT or Autopilot to make you the class by telling them the payload you have and that you want a class in C# to serialize into the payload.
You’ll get something like this.
using System.Text.Json.Serialization;
public class Payload
{
[JsonPropertyName("G_Column11")]
public string G_Column11 { get; set; }
[JsonPropertyName("G_Column22")]
public string G_Column22 { get; set; }
[JsonPropertyName("G_Column33")]
public string G_Column33 { get; set; }
[JsonPropertyName("$schema")]
public string Schema { get; set; }
// Parameterless constructor
public Payload()
{
G_Column11 = string.Empty;
G_Column22 = string.Empty;
G_Column33 = string.Empty;
Schema = string.Empty;
}
// Constructor to populate all fields
public Payload(string column11, string column22, string column33, string schema)
{
G_Column11 = column11;
G_Column22 = column22;
G_Column33 = column33;
Schema = schema;
}
}
Then in order to use the code its super easy.
var payload = new Payload("", "", "", "http://json-schema.org/draft-07/schema#");
string jsonString = JsonSerializer.Serialize(payload);
Please please stop messing around trying to construct JSON strings manually.
Build a class and serialize them, its super accessible to do with AI helping you make a class.