JSON 软件包

The JSON 软件包 enables you to extract and parse information from JSON data sources. It allows you to manipulate the JSON data, such as adding or updating values within a JSON string, parsing JSON strings into objects using node path, and converting JSON strings to dictionaries and vice versa.

JSON 软件包 plays a crucial role in seamlessly integrating automation workflows with web services and APIs that use JSON for data exchange.

Benefits

  • JavaScript Object Notation (JSON) is a lightweight, easy-to-understand, extensible format for storing, transporting, and retrieving data. JSON uses key-value pairs of data and delivers faster data interchange and web service results.
  • Most REST Web Services (APIs), some configuration files, and many NoSQL databases such as MongoDB commonly use JSON because of its flexible format for data exchange. It is text-based, lightweight, and has an easy-to-parse data format, which means it requires no additional code to understand and interpret the provided data.
  • JSON files can be great for storing and retrieving configuration data your automation might reference when determining server, environment-specific, or folder-share details.
  • JSON's flexible structure efficiently accommodates various data types and complex data hierarchies.

JSON data types

The values in JSON must be of following data type:
  • Strings
  • Numbers
  • Object (JSON Object)
  • Array
  • Booleans
Note: The value NULL is not supported in Automation 360. Therefore, when you extract JSON data and convert it to a dictionary variable, any null values in the JSON string are not converted, as dictionary variables do not support null values. However, if the JSON contains an empty string ("") instead of null, it will be successfully converted to a dictionary variable.

Understanding JSON structures

In JSON, data is mainly stored in two structures:
  • Objects: Objects in JSON are collections of key, value pairs enclosed in curly braces {}. Each key is a string enclosed with quotes (““) followed by a colon (:) , and commas (,) are used to separate the key, value pairs.
    Example:
    {"name ": "John", "age": "30", "city": Detroit}
  • Arrays: Arrays are ordered lists of values, enclosed in square brackets []. Values within an array are separated by commas (,).
    Example:
    ["John", "Annie", "Shane"]

Using JSON 软件包

Use the 操作 in the JSON 软件包 in the following order:
  1. Start the JSON session using the Start session 操作. Use this session name for all corresponding 操作.
  2. Use the different 操作 available in the JSON package to automate JSON related tasks.
  3. End the session using the End session 操作 to complete a task.

操作 in the JSON 软件包

The JSON 软件包 includes the following 操作:
Note: When you create an automation on the macOS platform, a confirmation window prompts you to grant app permissions in macOS. See this topic for a list of prompt messages and instructions on managing app permissions.

macOS 上的应用程序权限

操作 Description
Start session Start a new JSON session based on the specified JSON data source. See 在 JSON 中开始会话 操作.
Add node value Add a new node to the JSON specified in Start session data source. See 添加节点值.
Convert Dictionary to JSON Converts the content of a Dictionary variable to JSON format. See 将字典转换为 JSON.
Convert JSON to Dictionary Extract the contents of the JSON data source to a Dictionary variable. See 将 JSON 转换为字典.
Get node list Retrieves the list of nodes for a node path. See 在 JSON 中获取节点列表 操作.
Get nodes Extracts the key values from the JSON source. See Get nodes in JSON
Get node value Retrieves the value of a node from the JSON source. See 在 JSON 中获取节点值 操作.
Update node value Update the value of a node in the JSON data source. See 更新节点值.
Validate Validates the syntax, structure, and schema of the JSON data source. See Validate action
End session Closes a JSON session. See 在 JSON 中结束会话 操作.

More resources