activities
latest
false
UiPath logo, featuring letters U and I in white
Developer Activities
Last updated Dec 11, 2024

Deserialize JSON

UiPath.WebAPI.Activities.DeserializeJson

Description

Deserializes the JSON string or sample to a JObject.

Project compatibility

Windows - Legacy | Windows | Cross-platform

Windows, Cross-platform configuration

  • JSON String - The string containing the JSON to be deserialized. The JSON should be written without indents, and between double quotes. Strings inside the JSON should be written with single quotes. For example, the following JSON is valid: "{'TenancyName': 'Documentation', 'UsernameOrEmail': 'Documentation', 'Password': 'Documentation'}".

Advanced options
Input
  • JSON Sample - The JSON sample for the output structure. The activitiy converts this sample into a similar object which you can use during design time.

  • Input Type - A dropdown list that enables you to select the argument type of the object to deserialize.

Output

  • JSON object - The deserialized JSON, as a Newtonsoft.Json.Linq.JObject variable. For more information on Newtonsoft.Json.Linq.JObject objects, go here.

Windows - Legacy configuration

Properties panel

Common

  • DisplayName - The display name of the activity.

Input

  • JSON Sample - The JSON sample for the output structure. The activitiy converts this sample into a similar object which you can use during design time.

  • JsonString - The string containing the JSON to be deserialized. The JSON should be written without indents, and between double quotes. Strings inside the JSON should be written with single quotes. For example, the following JSON is valid: "{'TenancyName': 'Documentation', 'UsernameOrEmail': 'Documentation', 'Password': 'Documentation'}".

Misc

  • Private - If selected, the values of variables and arguments are no longer logged at Verbose level.
  • TypeArgument - A drop-down list that enables you to select the type of output returned. The provided JSON string will be converted to an object of the selected type.

Output

  • JsonObject - The deserialized JSON, as a Newtonsoft.Json.Linq.JObject variable. For more information on Newtonsoft.Json.Linq.JObject objects, go here.

Example of Using the Deserialize Json Activity

The Deserialize Json activity is used for extracting data from .json files and strings.
To exemplify how to use this activity, we have created an example that uses the Deserialize Json activity for extracting the age of a person from a .json file.

This is how the automation process can be built:

  1. Open Studio and create a new Process.
  2. Drag a Sequence to the Workflow Designer.

    • Create the following variables:

      Variable Name

      Variable Type

      Default Value

      JsonText

      String

       

      JsonObj

      JObject

       

      Age

      GenericValue

       
  3. Drag a Read Text File activity inside the sequence container.

    • In the Properties panel, add the value "JsonString.txt" in the FileName field.
    • Add the variable JsonText in the Content field.
  4. Add a Deserialize JSON activity after the Read Text File activity.

    • In the Properties panel, add the variable JsonText in the JsonString field and the variable JsonObj in the JsonObject field.
    • Select the value Newtonsoft.Json.Linq.JObject from the TypeArgument drop-down list.
  5. Place an Assign activity under the Deserialize JSON activity.

    • Add the variable Age in the To field and the expression JsonObj.SelectToken("age").ToString in the Value field.
  6. Drag a Write Line activity after the Assign activity.

    • Add the variable Age in the Text field.
  7. Run the process. The robot extracts the age value from the .json file and displays it in the Output panel.

Here you can download an example.

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.