Video: See the Community video on using JSON tasks in a Business Process.
JSON - Create
This task initializes a JSON variable or parameter as an empty JSON body.
Parameter | Type | Description |
---|---|---|
JSON | JSON | The resulting JSON body. |
JSON - Read From Type
This task converts either a String or a Storage Node to a JSON object.
Parameter | Type | Description |
---|---|---|
Result | JSON | The resulting JSON object. |
Data to Read | String or Storage node | The source data to be converted to a JSON object. |
JSON - Get
This task gets an object (of type String, Long, Double Boolean, List, Dictionary, or JSON) from the root of the JSON object with the specified name.
Parameter | Type | Description |
---|---|---|
JSON | JSON | The source JSON object. |
Name | String | The name of the JSON object to be retrieved from the root of the source JSON object. |
Result | <String, Long, Double, Boolean, List, Dictionary, or JSON> | The data with the specified name at the root of the JSON object. |
JSON - Get By Pointer
(Available in CIC Studio 5.2.18 and above) The task can be used to fetch a particular value of a key in a JSON or a JSONArray without having to loop through the JSON using the JSON-Get task.
The task accepts three Properties:
Parameter | Type | Description |
---|---|---|
JSON | JSON, Storage Node & String | JSON input |
Pointer | String | String of path to Key |
Result | String, Long, Double, Boolean, List, Dictionary & JSON | Output |
JSON: This is the input JSON. The allowed datatypes are JSON, StorageNode, or String. While the datatype can be any of the above three, the data must be valid JSON.
Pointer: A pointer identifies the path to a certain key to access; this can be any string literal or string variable.
- The pointer starts with /
- Each segment is separated by /
- Each segment can be interpreted as either an array index or an object key.
- If we want to access the first element in order_type which is a JSON array we can use the index (index starts from zero).
Pointer: /customer/order_type/0
In the given context, "customer" represents a JSON object, and "order_type" is a JSONArray that we wish to access. The "0" refers to the index of the specific element within that JSONArray.
Result: The result can be stored in the following datatypes: String, Long, Double, Boolean, List, Dictionary, or JSON.
Usage: Consider the following input JSON. If we want to access the value of the “email” key, here’s how the JSON Get By Pointer task could be used:
{
"id": 101,
"total_price_usd": "5.15",
"customer": {
"total_spent": "5.15",
"last_order_name": "#1050",
"last_order_id": 1012673151019,
"tax_exempt": false,
"created_at": "2018-03-08T16:04:34-05:00",
"last_name": "Geiger",
"verified_email": true,
"accepts_marketing_updated_at": "2018-12-31T11:06:21-05:00",
"tags": "password page, prospect",
"orders_count": 1,
"updated_at": "2019-04-09T14:53:13-04:00",
"accepts_marketing": true,
"admin_graphql_api_id": "gid://shopify/Customer/498608504875",
"currency": "USD",
"id": 498608504875,
“order_type”:[“PO”,”SO”,”ACK”],
"marketing_opt_in_level": "single_opt_in",
"state": "disabled",
"a/b": 1,
"first_name": "Will",
"email": "wgeiger@cleo.com"
}
}
Parameter | Type | Description |
---|---|---|
JSON | inputJSON | inputJSON, which can be stored in String, JSON, or StorageNode datatypes. |
Pointer | /customer/email | The task fetches the value of “email” within the “customer” |
Result | emailId | The result from the pointer /customer/email will be stored in the emailId variable. This can be String, Long, Double, Boolean, List, Dictionary, or JSON. |
Here’s another example: If the input JSON contains some special characters in the key...
{
"orders": ["bar", "baz"],
"": 0,
"sales/order": 1,
"c%d": 2,
"LastOrder^Name": “gieger”,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
}
...then the Pointers access the values as follows:
Pointer | Result |
---|---|
/orders | ["bar", "baz"] |
/orders/0 | “bar” |
/” | 0 |
/sales~1order | 1 |
/c%d | 2 |
/LastOrder^Name | gieger |
/g|h | 4 |
/i\j | 5 |
/k"l | 6 |
/ | 7 |
/m~0n | 8 |
Error Reporting and Troubleshooting
If the Pointer is syntactically wrong and is not available in the input JSON, the appropriate log message will appear in the Auditor Log.
If the input JSON is empty or syntactically wrong, an appropriate log message will appear in the Auditor Log.
If it is not able to convert the output based on the datatype given in the result, an appropriate error will be shown.
JSON - Set
This task sets an object (of type String, Long, Double Boolean, List, Dictionary, or JSON) in the root of the JSON object with the specified name.
Parameter | Type | Description |
---|---|---|
JSON | JSON | The source JSON object that data will be added to. |
Name | String | The name of the object to be set in the root of the source JSON object. |
Value | <String, Long, Double, Boolean, List, Dictionary, or JSON> | The data to be set in the root of the source JSON object. |
JSON - To Dictionary
This task converts a JSON object to a dictionary
Parameter | Type | Description |
---|---|---|
JSON | JSON | The source JSON object. |
Result | Dictionary | The converted dictionary representation of the source JSON object. |
JSON - To List
This task converts a JSON object to a list. Assumes the JSON object being converted is a JSON array, otherwise a runtime exception will be thrown.
Parameter | Type | Description |
---|---|---|
JSON | JSON | The source JSON object. |
Result | List | The converted list representation of the source JSON object. |
JSON - To Storage Node
This task converts a JSON object to a Storage Node.
Parameter | Type | Description |
---|---|---|
JSON | JSON | The source JSON object. |
To Storage Node | Storage node | The storage node that contains the data from the source JSON object. |
Comments
0 comments
Please sign in to leave a comment.