UiPath Documentation
activities
latest
false
Important :
Veuillez noter que ce contenu a été localisé en partie à l’aide de la traduction automatique. La localisation du contenu nouvellement publié peut prendre 1 à 2 semaines avant d’être disponible.

Activités du développeur.

Deserialize JSON

UiPath.WebAPI.Activities.DeserializeJson

Description

Deserializes the JSON string or sample to a JSON object. By default, the result is a JObject, but you can choose a different output type using the Output type property.

Compatibilité du projet

Windows - Héritage | Windows | Multiplate-forme

Prérequis

To configure the Serializer settings property using data mapping, use Studio 25.10 or later. In earlier Studio versions, this property uses the Expression Editor window instead.

Windows, configuration multiplate-forme

  • 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 - A sample of the JSON used to generate the output object properties. The sample must be in JSON format. The activity converts this sample into a similar object that you can use during design time.

Options avancées

Entrée
  • Serializer settings - Custom deserializer settings to be used when deserializing the JSON string. Use this property when you want to fully control how the JSON string is deserialized.
  • Output type - A drop-down list that lets you choose the argument type of the object to deserialize into.
    Remarque :

    In Studio Web, generating the output structure from the JSON Sample property makes the Output type property read-only.

Sortie
  • JSON object - The deserialized JSON, returned as an object of the type selected in the Output type property. When the default type is used, the result is a Newtonsoft.Json.Linq.JObject variable. Read more information on Newtonsoft.Json.Linq.JObject objects.

Example of using the JSON Sample

The JSON Sample property generates the output object structure at design time from a representative JSON snippet. After you provide a sample, the activity infers a matching type and assigns it to the Output type property, so you can reference the deserialized values by name in downstream activities instead of querying them with SelectToken.

Remarque :

The JSON Sample property is a design-time helper. It is available in Studio Web and in Studio versions that support custom type inference. When these features are not available, the property is hidden.

To exemplify how to use the JSON Sample, we extract a person's name and city from a JSON string:

  1. Add a Deserialize JSON activity to your workflow.

  2. In the JSON String field, enter the JSON to deserialize. For example: "{'name': 'John Doe', 'age': 30, 'address': {'city': 'New York'}}".

  3. In the JSON Sample field, paste a representative sample with the same structure:

    {
      "name": "John Doe",
      "age": 30,
      "address": {
        "city": "New York"
      }
    }
    {
      "name": "John Doe",
      "age": 30,
      "address": {
        "city": "New York"
      }
    }
    

    The activity reads the sample and generates an output object that mirrors this structure. The Output type property updates to the generated type.

  4. In a subsequent activity, reference the deserialized values directly through the property names defined in your sample, for example JsonObject.name and JsonObject.address.city, instead of using JsonObject.SelectToken("name").

Résultat

The output object exposes the properties from your sample, so JsonObject.name returns John Doe and JsonObject.address.city returns New York without querying the JSON with SelectToken.

Example of using Serializer settings

When no data mapping is available for the Serializer settings property, configure it in the Expression Editor using one of the following code snippets. For more information, see the Newtonsoft documentation.

VB.NET

New JsonDeserializationSettings With {
.MissingMemberHandling = JsonMissingMemberHandling.Ignore,
.NullValueHandling = JsonNullValueHandling.Ignore,
.DateParseHandling = JsonDateParseHandling.DateTime,
.DateTimeZoneHandling = JsonDateTimeZoneHandling.Utc,
.FloatParseHandling = JsonFloatParseHandling.Double
}
New JsonDeserializationSettings With {
.MissingMemberHandling = JsonMissingMemberHandling.Ignore,
.NullValueHandling = JsonNullValueHandling.Ignore,
.DateParseHandling = JsonDateParseHandling.DateTime,
.DateTimeZoneHandling = JsonDateTimeZoneHandling.Utc,
.FloatParseHandling = JsonFloatParseHandling.Double
}

C#

new JsonDeserializationSettings
{
MissingMemberHandling = JsonMissingMemberHandling.Ignore,
NullValueHandling = JsonNullValueHandling.Ignore,
DateParseHandling = JsonDateParseHandling.DateTime,
DateTimeZoneHandling = JsonDateTimeZoneHandling.Utc,
FloatParseHandling = JsonFloatParseHandling.Double
}
new JsonDeserializationSettings
{
MissingMemberHandling = JsonMissingMemberHandling.Ignore,
NullValueHandling = JsonNullValueHandling.Ignore,
DateParseHandling = JsonDateParseHandling.DateTime,
DateTimeZoneHandling = JsonDateTimeZoneHandling.Utc,
FloatParseHandling = JsonFloatParseHandling.Double
}

Configuration Windows - Héritage

Panneau propriétés

Commun
  • NomAffichage (DisplayName) - Nom affiché de l'activité.
Entrée
  • JSON Sample - The JSON sample for the output structure. The activity converts this sample into a similar object which you can use during design time.
  • Chaîne Json - Chaîne contenant le fichier JSON à désérialiser. Écrivez le JSON sans retrait et entre guillemets. Les chaînes à l'intérieur du fichier JSON doivent être écrites avec des apostrophes. Par exemple, le fichier JSON suivant est valide : « {’TenancyName » : ’Documentation’, ’UsernameOrEmail’ : ’Documentation’, ’Password’ : ’Documentation’} ».
Divers
  • Privé (Private) - Si cette option est sélectionnée, les valeurs des variables et des arguments ne sont plus enregistrées au niveau Détaillé (Verbose).
  • TypeArgument : une liste déroulante qui permet de sélectionner le type de sortie renvoyé. La chaîne JSON fournie sera convertie en un objet du type sélectionné.
Sortie

Exemple d’utilisation de l’activité Deserialize Json

L'activité Désérialiser Json est utilisée pour extraire des données des fichiers et des chaînes JSON.

Pour illustrer comment utiliser cette activité, nous avons créé un exemple qui effectue l'activité Désérialiser Json pour extraire l'âge d'une personne depuis un fichier JSON.

Voici comment le processus d'automatisation peut être créé :

  1. Ouvrez Studio et démarrez un nouveau Processus.
  2. Drag a Sequence to the Workflow Designer.
    • Créez les variables suivantes :

      Nom de variableTypes de variablesValeur par défaut
      JsonTextChaîne de caractères (string)
      JsonObjObjetJ
      AgeValeurGénérique
  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. Ajoutez une activité Désérialiser JSON (Deserialize JSON) sous l’activité Lire le fichier texte (Read Text File).
    • 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. Faites glisser une activité Écrire une ligne (Write Line) sous l’activité Affecter (Assign).
    • Ajoutez la variable Age dans le champ Texte.
  7. Run the process. The robot extracts the age value from the .json file and displays it in the Output panel.

Ici, vous pouvez télécharger un exemple.

Cette page vous a-t-elle été utile ?

Connecter

Besoin d'aide ? Assistance

Vous souhaitez apprendre ? UiPath Academy

Vous avez des questions ? UiPath Forum

Rester à jour