JSON Object - Decode

IMPORTANT: This is a legacy activity and is no longer supported in Automate Desktop version 11.7.0 or later. Existing tasks currently using this activity will continue to run, but it is not recommended to use this activity with new tasks.

Declaration

<AMJSON ACTIVITY="json_deserialize" JSONSTRING="text" TYPENAME="text" RESULTSTRUCTURE="text" MAXLENGTH="number"/>

Related Topics

Description

Converts data in JSON format into structural data such as an Automate Desktop data object or array.

Practical usage

JSON is primarily used to transmit data between a server and web application, as an alternative to XML. Use this activity to decode data that was previously encoded into JSON format with the use of the JSON Object - Encode activity. You can use this method to convert JSON-encoded data into a data object or array that you can easily read and work with. For example, you can use a Loop block to loop through all of the objects in a set of data and update them in a database.

Parameters

General

Property Type Required Default Markup Description
JSON string Text Yes (Empty) JSONSTRING="text" The JSON-formatted string to decode into an object.
Create and populate object of JSON string Text Yes (Empty) RESULTSTRUCTURE="sample" The name of the object to use to store JSON decoded data. For debugging purposes, when a JSON string is decoded, the object into which it is stored is displayed as a type "structure" or "array" in the Variables Debug panel.

Advanced

Property Type Required Default Markup Description
Predefined type name (Optional) Text No (Empty) TYPENAME="sample" Specifies the name of a predefined type. When any type names are predefined, clicking the box displays those names in a list. This parameter is optional.
Maximum JSON string size in MB (Optional) Number No (Empty) MAXLENGTH="1" Specifies the maximum JSON string size in megabytes (MB). This parameter is optional.

Description

Error Causes

On Error

Example

NOTE:
  • Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
  • To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.

Description

This sample task decodes JSON-formatted data into an object and re-encodes the object back to a JSON-formatted string.

Copy
<AMVARIABLE NAME="theString" VALUE="" />
<AMJSON ACTIVITY="json_deserialize" JSONSTRING="[&#xD;&#xA; {&#xD;&#xA; &quot;id&quot;: &quot;0001&quot;,&#xD;&#xA; &quot;type&quot;: &quot;donut&quot;,&#xD;&#xA; &quot;name&quot;: &quot;Cake&quot;,&#xD;&#xA; &quot;ppu&quot;: 0.55,&#xD;&#xA; &quot;batters&quot;:&#xD;&#xA; {&#xD;&#xA; &quot;batter&quot;:&#xD;&#xA; [&#xD;&#xA; { &quot;id&quot;: &quot;1001&quot;, &quot;type&quot;: &quot;Regular&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;1002&quot;, &quot;type&quot;: &quot;Chocolate&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;1003&quot;, &quot;type&quot;: &quot;Blueberry&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;1004&quot;, &quot;type&quot;: &quot;Devils Food&quot; }&#xD;&#xA; ]&#xD;&#xA; },&#xD;&#xA; &quot;topping&quot;:&#xD;&#xA; [&#xD;&#xA; { &quot;id&quot;: &quot;5001&quot;, &quot;type&quot;: &quot;None&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;5002&quot;, &quot;type&quot;: &quot;Glazed&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;5005&quot;, &quot;type&quot;: &quot;Sugar&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;5007&quot;, &quot;type&quot;: &quot;Powdered Sugar&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;5006&quot;, &quot;type&quot;: &quot;Chocolate with Sprinkles&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;5003&quot;, &quot;type&quot;: &quot;Chocolate&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;5004&quot;, &quot;type&quot;: &quot;Maple&quot; }&#xD;&#xA; ]&#xD;&#xA; },&#xD;&#xA; {&#xD;&#xA; &quot;id&quot;: &quot;0002&quot;,&#xD;&#xA; &quot;type&quot;: &quot;donut&quot;,&#xD;&#xA; &quot;name&quot;: &quot;Raised&quot;,&#xD;&#xA; &quot;ppu&quot;: 0.55,&#xD;&#xA; &quot;batters&quot;:&#xD;&#xA; {&#xD;&#xA; &quot;batter&quot;:&#xD;&#xA; [&#xD;&#xA; { &quot;id&quot;: &quot;1001&quot;, &quot;type&quot;: &quot;Regular&quot; }&#xD;&#xA; ]&#xD;&#xA; },&#xD;&#xA; &quot;topping&quot;:&#xD;&#xA; [&#xD;&#xA; { &quot;id&quot;: &quot;5001&quot;, &quot;type&quot;: &quot;None&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;5002&quot;, &quot;type&quot;: &quot;Glazed&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;5005&quot;, &quot;type&quot;: &quot;Sugar&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;5003&quot;, &quot;type&quot;: &quot;Chocolate&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;5004&quot;, &quot;type&quot;: &quot;Maple&quot; }&#xD;&#xA; ]&#xD;&#xA; },&#xD;&#xA; {&#xD;&#xA; &quot;id&quot;: &quot;0003&quot;,&#xD;&#xA; &quot;type&quot;: &quot;donut&quot;,&#xD;&#xA; &quot;name&quot;: &quot;Old Fashioned&quot;,&#xD;&#xA; &quot;ppu&quot;: 0.55,&#xD;&#xA; &quot;batters&quot;:&#xD;&#xA; {&#xD;&#xA; &quot;batter&quot;:&#xD;&#xA; [&#xD;&#xA; { &quot;id&quot;: &quot;1001&quot;, &quot;type&quot;: &quot;Regular&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;1002&quot;, &quot;type&quot;: &quot;Chocolate&quot; }&#xD;&#xA; ]&#xD;&#xA; },&#xD;&#xA; &quot;topping&quot;:&#xD;&#xA; [&#xD;&#xA; { &quot;id&quot;: &quot;5001&quot;, &quot;type&quot;: &quot;None&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;5002&quot;, &quot;type&quot;: &quot;Glazed&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;5003&quot;, &quot;type&quot;: &quot;Chocolate&quot; },&#xD;&#xA; { &quot;id&quot;: &quot;5004&quot;, &quot;type&quot;: &quot;Maple&quot; }&#xD;&#xA; ]&#xD;&#xA; }&#xD;&#xA;]" RESULTSTRUCTURE="decoded" />
<AMJSON ACTIVITY="json_serialize" RESULTVARIABLE="theString" RESULTSTRUCTURE="decoded" />
<AMSHOWDIALOG>%theString%</AMSHOWDIALOG>