Unable to convert the Jsonobject to Json array

Hi all,

Sometimes, I am unable to convert the Json object to the Json array.

The below is the output string I am receiving as an output from deserialized activity.

“{”“projects”“: {”“project”“: {
““domain-name””: ““TRAINING””,
““create-from-domain””: ““deFAULT””,
““is-auto-mail-enabled””: false,
““description””: ““Created on 8/30/2023 5:10:49 AM””,
““db-server-name””: ““testawssqld01"”,
““uid””: ““e75a4a25-9627-4658-ab93-0dd71dc3ed6b””,
““id””: 412,
““users-quota””: -1,
““domain-id””: 2,
““is-qpm-auto-calc-enabled””: true,
““is-active””: true,
““is-unicode””: false,
““db-name””: ““training_test_test_kg_nongxp_db””,
““version””: ““15.50"”,
““search-language””: ““English””,
““project-type””: ““Standard””,
““is-template””: false,
““exception-file””: “”””,
““is-db-native-auth””: false,
““db-type””: 2,
““name””: ““Test_Test_KG_NonGxp””,
““physical-directory””: “”\\test\share\ProgramData\MF\Test\repository\qc\TRAINING_2\Test_Test_KG_NonGxp\”",
““db-connstr-format””: ““jdbc:sqlserver://testld01:1433"”,
““create-from-project””: ““Templet””,
““has-vcs-db””: true
}}}”

While converting this as an array I am facing the Below error.

In the Json array activity, I am using the Code as

"JSONObject.SelectToken(“projects”)(“project”).ToString "

The below is the error I am receiving

Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path ‘’, line 1, position 1

Do we have any way that we can directly convert the fetch what we required from the string.

Kindly do the needfull.

Thanks
Sreenivasa

Here we can detect, that is not an JArray as the [ is not missing
grafik

We could do like this:
grafik
output - myJObject

then we can create JArray by:


JArray.FromObject({myJObject("projects")("project")})

Maybe your intention was also about:

Hi thanks for the quick responce.

My intension is I need to get few values from the Json string.

I need the domain name from this string.

““domain-name””: ““TRAINING””,

but I am failing to get this domain name form the input what I received as a responce

So can we achieve directly from the output of Json string.

Thanks

we could do directly:
grafik

Can iterate dynamically over all Properties:

Maybe you can tell more about the final goal / use case

1 Like

Can we finalize the topic and get it closed
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

Hi I am trying to loog this,

Could you pleas ehelp me with what is the argument type for for each

I am using the Jobject.

But I am getting the below error

For Each: Unable to cast object of type ‘Newtonsoft.Json.Linq.JProperty’ to type ‘Newtonsoft.Json.Linq.JObject’.

Thanks

When looping over the Properties as mentioned above then we set the typeArgument to JProperty

With myLoopVar.Name we access the Property name
With myLoopVar.Value.Value(Of String) we access e.g. the value as String

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