# Deserialize JSON

> `UiPath.WebAPI.Activities.DeserializeJson`

`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'}".
* **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.

### **Advanced options**

### **Input**

* **Input Type -** A dropdown list that enables you to select the argument type of the object to deserialize.
  :::note
  In Studio Web, parsing the sample object via the **JSON Sample** property makes the **Input Type** property read-only.
  :::

#### Output
* **JSON object** - The deserialized JSON, as a `Newtonsoft.Json.Linq.JObject` variable. Read more information on [`Newtonsoft.Json.Linq.JObject` objects](https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Linq_JObject.htm).

## 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. Write the JSON 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. Read more information on[`Newtonsoft.Json.Linq.JObject` objects](https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Linq_JObject.htm).

## 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](https://www.uipath.com/hubfs/Activities/DeserializeJson.zip) you can download an example.
