JSON Object - Decode
Declaration
<AMJSON ACTIVITY="json_deserialize" JSONSTRING="text" TYPENAME="text" RESULTSTRUCTURE="text" MAXLENGTH="number"/>
Description
Converts data in JSON format into structural data such as an Automate 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. |
Example
- 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.
<AMVARIABLE NAME="theString" VALUE="" />
<AMJSON ACTIVITY="json_deserialize" JSONSTRING="[
 {
 "id": "0001",
 "type": "donut",
 "name": "Cake",
 "ppu": 0.55,
 "batters":
 {
 "batter":
 [
 { "id": "1001", "type": "Regular" },
 { "id": "1002", "type": "Chocolate" },
 { "id": "1003", "type": "Blueberry" },
 { "id": "1004", "type": "Devils Food" }
 ]
 },
 "topping":
 [
 { "id": "5001", "type": "None" },
 { "id": "5002", "type": "Glazed" },
 { "id": "5005", "type": "Sugar" },
 { "id": "5007", "type": "Powdered Sugar" },
 { "id": "5006", "type": "Chocolate with Sprinkles" },
 { "id": "5003", "type": "Chocolate" },
 { "id": "5004", "type": "Maple" }
 ]
 },
 {
 "id": "0002",
 "type": "donut",
 "name": "Raised",
 "ppu": 0.55,
 "batters":
 {
 "batter":
 [
 { "id": "1001", "type": "Regular" }
 ]
 },
 "topping":
 [
 { "id": "5001", "type": "None" },
 { "id": "5002", "type": "Glazed" },
 { "id": "5005", "type": "Sugar" },
 { "id": "5003", "type": "Chocolate" },
 { "id": "5004", "type": "Maple" }
 ]
 },
 {
 "id": "0003",
 "type": "donut",
 "name": "Old Fashioned",
 "ppu": 0.55,
 "batters":
 {
 "batter":
 [
 { "id": "1001", "type": "Regular" },
 { "id": "1002", "type": "Chocolate" }
 ]
 },
 "topping":
 [
 { "id": "5001", "type": "None" },
 { "id": "5002", "type": "Glazed" },
 { "id": "5003", "type": "Chocolate" },
 { "id": "5004", "type": "Maple" }
 ]
 }
]" RESULTSTRUCTURE="decoded" />
<AMJSON ACTIVITY="json_serialize" RESULTVARIABLE="theString" RESULTSTRUCTURE="decoded" />
<AMSHOWDIALOG>%theString%</AMSHOWDIALOG>