Deserialize

You can use the Deserialize function to convert JSON string data into strongly typed objects for easier manipulation of object properties in scripts.

When to use

You can use this function to:

  • Convert JSON responses from APIGet, APIPost, or external API calls into strongly typed objects for easier data handling.
  • Parse JSON configuration strings stored in parameters or profiles into usable objects.

When not to use

You cannot use this function for simple non-JSON strings. The input needs to have valid JSON-formatted data.

Syntax

T Deserialize<T>(string stringData);
Note: 
  • The Deserialize function is a generic deserialization method. The function takes a serialized string and returns an instance of type T created by parsing the string.
  • The T parameter is a compile-time type parameter not a runtime parameter. The parameter specifies the target CLR type, such as MyDto, List, or int[].
  • The compiler can infer T from the call site, such as Deserialize(json), or from the type of the variable receiving the result.
  • Some APIs can have constraints, for example T : class. The syntax shown here has no constraints, so any type is allowed.
  • For a complex type, the serializer needs a way to construct the type, such as a public parameter less constructor or a custom converter.
  • For polymorphic scenarios, explicit settings or type-discriminator metadata is required.

Parameters

Parameter Type Required Description
stringData string Yes The JSON string value that has to be converted into object

Return Value

The application returns an object of the specified type containing the deserialized JSON data.

Prerequisites

  • The Deserialize function has no permission requirements.
  • The function has technical constraints related to valid JSON format and type compatibility.

Examples

Example 1
Deserialize JSON string into object.
// Create a JSON string variable
string jsonString = "[\"Project Code\",\"Description\",\"Customer Name\",\"Total Cost\"]";

// Deserialize JSON string into a string array
string[] valueArray = Deserialize<string[]>(jsonString);

// Deserialize JSON string into a custom class object
myClass myClassObj = Deserialize<myClass>(dataString);