I have this json, and I want to extract for each entity the entity id, the value, and the confidence. I am using a for each (item in json) and item.name for the entity id which is working fine. However, much trial and error has not helped me extract the value or confidence.
Normally I’d name the fields I want from the deserialised json, eg json.root(“sentiment”).item(“value”).value(of string). However, this does not apply in the for each scenario, when the number and types of entity could change. Furthermore, this only goes two levels down, and I require 3 levels for this.
This is interesting, but it’s not quite what I wanted. This will work well for mass entries, but I have single calls and I need to be able to use the values in the output more easily.
The output this gives me is:
_text
entities/sentiment/0/confidence
entities/sentiment/0/value
msg_id
I am excited to work
0.981648564
positive
1bdu1ZV0isn9tkpeh
However, I need something more akin to:
Entity ID
Value
Confidence
Sentiment
positive
0.981648564
I am assuming every entity will have a value and confidence result, but I do not know how many entities I will return (and indeed I may add more later and want my workflow to be easy to maintain).
I would consider using this as a holding table, but I’d end up with a pair of headers for each entity, and this would quickly become problematic to convert to my format.
An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
Newtonsoft.Json.JsonReaderException: Error reading JArray from JsonReader. Current JsonReader item is not an array: String. Path ‘’, line 1, position 11.
at Newtonsoft.Json.Linq.JArray.Load(JsonReader reader, JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JArray.Parse(String json, JsonLoadSettings settings)
at UiPath.Web.Activities.DeserializeJsonArray.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
Yeah, I’m using deserialise json for the response, then for each entity I am trying to get the name, the value and the confidence. Sentiment is an entity, and you said this is an array.
if i deserialise jsonObject(“entities”).tostring into a new JObject, and use my usual .root(name).item(name).value(of string) then I get an error Assign: Accessed JArray values with invalid key value: “value”. Int32 array index expected.