Activities
latest
false
Banner background image
Integration Service Activities
Last updated Apr 23, 2024

IJsonObject type objects

When working with Sagemaker ML models, the response object is returned in JSON format and can differ greatly depending on the model employed. Users need to leverage Newtonsoft's JSON library from Studio to traverse and work with the JSON responses from Sagemaker. Some ML models return a response field with a singular value that can be accessed as a string, others contain arrays of multiple probabilities that can be matched with labels. Some examples include:

Example 1

{ "probabilities": [ 0.994889379, 0.00511063961 ] }{ "probabilities": [ 0.994889379, 0.00511063961 ] }
The response from a Sagemaker Get Inference step needs to be saved as an IJSONObject. This object can then be converted in a subsequent step to a JObject. Once this is done, you can use any of the methods available from Newtonsoft to parse and work with the JSON data. Looking at Example 1, you can perform newres.ToJObject("probabilities").ToList(0) to grab the probability 0.994889379.
Example 2
{
  "probabilities": [
    0.000404331338,
    0.000591270567,
    0.000552555488,
    0.000212208135,
    0.00052378932,
    ...
    0.990523789322
  ],
  "labels": [
    "background",
    "tench",
    "goldfish",
    "great white shark",
    "tiger shark",
    ...
    "tabby"
  ],
  "predicted_label": "tabby"
}{
  "probabilities": [
    0.000404331338,
    0.000591270567,
    0.000552555488,
    0.000212208135,
    0.00052378932,
    ...
    0.990523789322
  ],
  "labels": [
    "background",
    "tench",
    "goldfish",
    "great white shark",
    "tiger shark",
    ...
    "tabby"
  ],
  "predicted_label": "tabby"
}
  
Depending on your underlying ML model it may provide a singular value to use like a predicted_label from Example 2. In this case you could do newres.ToJObject("predicted_label") to get the value tabby.

Other tooling in Studio

Studio comes with built-in steps to create ForEach loops and If or Then conditions. The JObject queries can be combined with these steps to create more powerful workflows, like the example below:
docs image

Newtonsoft JSON Library

The JObject class in the Newtonsoft.Json library is a representation of a JSON object. It allows you to manipulate and work with JSON data in Studio Web.

Here are some of the most commonly used methods of the JObject class:

  1. Parse: This method is used to parse a string representation of a JSON object into a JObject instance.
  2. ToString: This method returns a string representation of the JSON object.
  3. Add: This method is used to add a new property to the JSON object.
  4. Remove: This method is used to remove a property from the JSON object.
  5. ContainsKey: This method returns a Boolean value indicating whether the JSON object contains a property with the specified key.
  6. GetValue: This method returns the value of the property with the specified key.
  7. SetValue: This method sets the value of the property with the specified key.
  8. Count: This property returns the number of properties in the JSON object.
  9. Properties: This property returns a collection of all the properties in the JSON object.
  10. DeepClone: This method creates a deep copy of the JSON object.
  • Other tooling in Studio
  • Newtonsoft JSON Library

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.