Covert text to json


Im trying to serialize my text “{SolutionId:123123,ClientId:123123}”

to Json format
but after using newtonsoft i get !


what is the pest practice to build json object and serialize it ?

i did try to write to text file but no luck :exclamation:
Im using C# any tips


Hi @Hazem_Saleh,

Use the Build JSON Object activity to create a JSON object with your desired properties. In your case, it would look something like this:

  "SolutionId": 123123,
  "ClientId": 123123



How about the following?



To explain why you’re having a problem…


…is not valid JSON. You’d need single quotes around SolutionId and CilentId. The solutions provided account for this.

1 Like

This is already serialized.
I think you want to Deserialize your text.

(This is also assuming you also fix the issues regarding quotes raised by RajKumar, Yoichi and Paul)

Thanks, but then i have to add to http as string! ?
im trying invoke code but seems not happy when i input the string for the Json converter !

Thanks everyone

You don’t want to use Invoke Code. You want to use an Assign acitivity to put the result into a variable.

I mean Paul, he’s got it backwards anyway. Yoichi showed deserializing a string to a JObject (jo) and then how to serialize the JObject.

There is a fundamental misunderstanding here by Hazem where he thinks he can/should serialize a string. Thats not logical. Yoichis code for example demonstrates serializing and deserializing but you end up back where you start.
I think we need to clarify the misunderstanding before any meaningful process can continue.

1 Like

you are right I’m just building this string, but still always missing the “” when i send it via api…

What is the best way around it

i followed the official example

But now how i can pair them!
Or this is ok for Json body!


What you created is a json array

If you need a jobject then use deserialize json activity and pass the string as below and output would be the jobject




how to format this im trying i got instead of {} should i add ( : ) as character ?

how to have obj.add with " !

I need it to look like {“SolutionId”:“123123”}

Im getting closer but very confused :stuck_out_tongue:

As I have been urging.
I think you need to stop for a minute and learn some fundamentals about what ‘Serializing’ and ‘Deserializing’ is and help explain to us what you are actually trying to achieve cause ‘Serializing a string’ makes no sense.

1 Like


What you created is a jarray and not jobject


Invoke Code way:

Hope this is clear


1 Like

I’d like to also share an opinion. Avoid Invoke Code like the plague, its hard to debug. You very very rarely need to use it. I think I used it once due to a bug in the compiler.

You are right!
i dont think i need that but was trying to figure it
I have two variable solutionid and clienID
im trying to achieve same as this result How to serialize and deserialize JSON using C# - .NET | Microsoft Learn

{"solutionid ":“1212”,“ClientID”:“1211”}

but couldn’t do the same in UiPath

Is that the main goal, you just want to duplicate some C# functionality for learning purposes? I’d definitely not use Invoke Code in that case as that surely defeats the point.

As I’ve stated before, getting to understand that you don’t serialize a string is the first step.

when having 2 variables like

then we can create the JObject / serialized JSON String by
Option 1:

Option 2:

as also other options are possible. The shown snippets can be used within Assign Activities


myDict = new Dictionary<string,string>{{"SolutionID",strSolutionID},{"ClientID",strClientID}};

Thanks alot its seems my problem i quite dont understand where to find the right type
if i use assign myDict its going to be Dictionary but cant find the type under browse for all type !
same for the second one Newtonsoft.Json.Linq.JObject.FromObject(myDict);


then click ok, ok