JSON Object- Encode

IMPORTANT: This is a legacy activity and is no longer supported in Automate 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_serialize" RESULTVARIABLE="text" TYPENAME="text" RESULTSTRUCTURE="text" MAXLENGTH="number"/>

Related Topics

Description

Converts structural data such as a data object or array to a JSON-formatted string.

Practical Usage

JSON is primarily used to transmit data between a server and web application, as an alternative to XML. This activity can be used to convert data objects or an array of objects to JSON format in order to effectively work with the data as text in a web page by using JavaScript. This lets you create a page where users interact with the data in the browser without requiring round trips to the server.

Parameters

General

Property Type Required Default Markup Description
Object name Text Yes (Empty) TYPENAME="text" The name of the object to convert to a JSON-formatted string.
Populate variable with JSON string Text Yes (Empty) RESULTVARIABLE="varName" The name of an existing variable to use to populate with the JSON-formatted string. For debugging purposes, when an object is encoded into a JSON string, the variable into which it is stored displays the current string value in the Variables Debug panel.
Format JSON string Yes/No Yes Yes FORMAT="NO" If selected (default), the JSON string is formatted with line breaks to make it easier to read and debug. If disabled, the JSON string output is a single line of code without line breaks to save space, which makes it more difficult to read and comprehend.

Advanced

Property Type Required Default Markup Description
Predefined type name (optional) Text No (Empty) RESULTSTRUCTURE="name" 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:
  • The sample AML code below can be copied and pasted directly into the Steps Panel of the Task Builder.
  • Parameters containing user credentials, files, file paths, and/or other information specific to the task must be customized before the sample code can run successfully.

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>