HTTP Request - Body

Hello,

I’m using a POST method to create a Test Data Queue, and I’ve verified it works perfectly through Postman. Here’s a snapshot for reference.

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.

Here’s the value I’m trying to use for ContentJsonSchema : "{"G_Column11":"","G_Column22":"","G_Column33":"","$schema":"http://json-schema.org/draft-07/schema#\“}”

Error Message :

Am I missing something here? Any suggestions or insights would be appreciated!

Thanks.

I suppose quotes in the string should be replaced by double quotes.
i.e. each \" should be \“”
Cheers

1 Like

Hi,

In Vb.net (UiPath) a quotation mark must be express as two quotation mark.
The following document may help you.

Regards

1 Like

@Gagan_AP

Replace quotes with double quotes like below

"{""G_Column11"":"""",""G_Column22"":"""",""G_Column33"":"""",""$schema"":""http://json-schema.org/draft-07/schema#""}"

1 Like

@Gagan_AP,

Try escaping \ with \\

How to Escape:

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"”.
2 Likes

Thanks @Darshan_Sable .
I have tried this but the API Body required – "{"G_Column11":"","G_Column22":"","G_Column33":"","$schema":"http://json-schema.org/draft-07/schema#\“}”

This Format only, else it’s throwing an null value error.

Hey @ashokkarale , Thanks for this. Can you please send me and final string, bit confused while adding the backslashes.

initial string = "{"G_Column11":"","G_Column22":"","G_Column33":"","$schema":"http://json-schema.org/draft-07/schema#\“}”

@Gagan_AP,

Pass it like this:

"""G_Column11"":"""",""G_Column22"":"""",""G_Column33"":"""",""$schema"":""http://json-schema.org/draft-07/schema#\""}"""

@ashokkarale

You missed the opening { curly bracket in your code block snippet :smiley:

1 Like

Thank you @loginerror for noticing that.. Just hope @Gagan_AP got it working :thinking:

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.

1 Like