How to create JSON that is a mixture of different types in the same hierarchy

Hi, everyone.

I am learning how to handle Json in UiPathStudio.
I would like to output a Json like (B) below.

As shown in (A), after setting the “dependencies” element to Dictionary<String, Object>, it can be set to the top-level Dictionary<String, Dictionary<String, Object>.
By setting it to a top-level Dictionary<String, Dictionary<String, Object>>.
I could output JSON without errors.

(A)
{
“dependencies”: {
“UiPath.Excel.Activities”: “[2.11.3]”,
“UiPath.System.Activities”: “[21.10.0]”
}
}

However, if I try to mix a String and a Dictionary type in the value part of the top-level Dictionary, as shown in (B) below, I got an error saying that the type cannot be converted.
(“Main.xaml” is a string type, but the “Uipath.Excel…” is a Dictionary Type, which is a different type)

“A compile error occurred while processing the argument ‘Value’:expression ““arbitrary string””.
Cannot convert value of type ‘String’ to ‘System.Collections.Generic.Dictionary(Of Sring, Object)’.”

What type specification would be required to output (B)? Or, what kind of UiPath activity settings do I need to use to output (B)?

(B)
{
“main”: “Main.xaml”,
“dependencies”: {
“UiPath.Excel.Activities”: “[2.11.3]”,
“UiPath.System.Activities”: “[21.10.0]”
},
“webServices”:
}

I use “Microsoft.Activities.Exctentions=2.0.6.9” to add to the dictionary, but you can use other methods as well.

I expect to use it heavily in the BODY element when making http requests to other systems in the future. So I want to understand the input and output of JSON accurately.

Thanks.

Hi @tspath1900

Let’s assume that Sring is a typo / copy-paste issue and String is correctly used for the datatype.

We can guess that you are further engaged in generating JSON. It looks like you are generating JSON based on dictionaries.

With a top-level Dictionary<String, Dictionary<String, Object>> you do define a very generic data type structure. However, it is also recommended to check, if a native JSON approach may be better will serve your needs.

Unfortunately the JSON example (looks like the project.json file) is less supporting a generic learning, but let’s try:

{
“main”: “Main.xaml”,
“dependencies”: {
“UiPath.Excel.Activities”: “[2.11.3]”,
“UiPath.System.Activities”: “[21.10.0]”
},
“webServices”: []
}

{ all other content} ← JObject


the properties:
{
main
dependencies
webservices
}
grafik


with values:
main: - string
dependencies: a collection of JObjects ~ Dictionary(Of String, String)
webservices: JArray ~ e.g. String list/array

Especially: “webServices”: will not fit to Dictionary<String, Dictionary<String, Object>>

Therefore the more generic definition: Dictionary<String, Object> would allow it as cross-checked with an opposite check with deserialization:

A dictionary construction process could look like this:
grafik

checked with Serialization
grafik

1 Like

Thanks for the reply.

I understand what you have written.
However, I don’t know how to represent these in UiPath Studio.

  1. I got to understood the need for definitions using JObject and JProperty by you wrote.
  2. I also got to understood “a dictionary construction process” by you wrote.

I have three questions.
a) How do I define “myDict” in the image in UiPath Studio?
I don’t know how to define it using JObject and JProperty in UiPath Studio.
I can declare variables of type JObject and JProperty, but do not know how make structured variables.

b) Is the image you attached a UiPath Studio image? I’ve never seen them in UiPath Studio.
d38e2f58e46d918edf7d7e1c2dfdb1cc1484bcbf_2_690x153
Where can I find this in the UiPath?

Unfortunately the JSON example (looks like the project.json file) is less supporting a generic learning

c) Are you saying that there are few opportunities to output JSON in a format like project.json? Or do you mean that it is not suitable for learning?

Thanks. I sincerely appreciate your help.

Of Sring

It was a typo when I wrote this post.

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