How can we pass boolean variable into http request body(JSON Format)?

Hi

I wanted to know how can we pass boolean variable into http request body using Json format?

Example :
“{”“empid”“:”“123"”,‘’‘isemployee"’:true}"
Here in place of true I wanted use boolean type variable . Can anyone suggest how can I proceed with this?

`String.Format("{{""empid"":""123"",""isemployee"": {0} }}", myBoolVar,toString.toLower)`

@Manisha24

// Define your boolean variable
isEmployee = True

// Create the JSON string with the boolean variable
jsonString = $"{{""empid"":""123"",""isemployee"":{isEmployee.ToString().ToLower()}}}"

Is there any other way of doing this?

"{""empid"":""123"",""‘isemployee"": " + YourBoolVar.ToString.ToLower + "}"

UPD1 - JSON Approach hint:
For sure we can parse the JSON String / Json Template … into JOBject and set the value by a variable with using JSON API e.g. Newtonsoft

1 Like

@Manisha24

// Define your boolean variable
isEmployee = True

// Create the JSON string with the boolean variable
jsonString = String.Format("{{""empid"":""123"",""isemployee"":{0}}}", isEmployee.ToString().ToLower())

Try this approach

1 Like

Thanks a lot!! This method worked for me

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.