UiPath Documentation
activities
latest
false
Developer activities

Create and Deserialize a JSON Array

Create a JSON array using Invoke Code and deserialize it with the Deserialize JSON Array activity.

The following example explains how to use activities such as Invoke Code and Deserialize Json Array to create a JSON array, deserialize it, and provide the list of extracted tokens. You can find these activities in the UiPath.WebAPI.Activities package.

This is how the automation process can be built:

  1. Open Studio and create a new Process.

  2. Drag a Sequence container in the Workflow Designer.

  3. Create the following variables:

    Variable NameVariable TypeDefault Value
    jsonAsStringString
    jsonAsArrayJArray
  4. Add an Invoke Code activity inside the Sequence.

    • Select the Edit Code button and add the following code in the opened window:

      Dim obj As ArrayList = New ArrayList()
      obj.Add("Starcraft")
      obj.Add("DOTA 2")
      obj.Add("FarCry")
      Out = JsonConvert.SerializeObject(obj)
      Dim obj As ArrayList = New ArrayList()
      obj.Add("Starcraft")
      obj.Add("DOTA 2")
      obj.Add("FarCry")
      Out = JsonConvert.SerializeObject(obj)
      
    • Once the code is added, select the OK button.

    • Select the Edit Arguments button and add the following argument:

      ArgumentDirectionTypeValue
      outOutStringjsonAsString
    • Once finished, select the OK button like in the following GIF:

  5. Add a Log Message activity after the Invoke Code activity.

    • Add the expression "JSON As String: "+jsonAsString in the Message field.
  6. Add a Deserialize Json Array activity after the Log Message activity.

    • Add the variable jsonAsString in the Json String field.
    • In the Properties panel, add the variable jsonAsArray in the JsonArray field.
  7. Add a For Each activity after the Deserialize Json Array activity.

    • Add the value token in the ForEach field.
    • Add the variable jsonAsArray in the VB expression field.
    • In the Properties panel, in the TypeArgument field, make sure you chose JValue.
  8. Add a Log Message activity inside the Body of the For Each activity.

    • Add the expression token.ToString in the Message field.

    This is how the workflow should look:

  9. Run the process. A JSON array is created, deserialized as a String and provided as a list of extracted tokens.

Here you can download an example.

Was this page helpful?

Connect

Need help? Support

Want to learn? UiPath Academy

Have questions? UiPath Forum

Stay updated