[en] Configuring JSON filter

目前还没有官方翻译。

[en] JSON Filter

[en] To learn more about filters in general, see section Understanding Filters.

[en] Use the JSON filter if your trigger receives JSON-encoded data. JSON filter allows you to use variables and values from your JSON file. The filter supports data extraction from JSON arrays.

注意

[en] Automation allows you to use all JSON data types. Read more about the available JSON data types here.

[en] While you can define the JSON file structure manually, NiceLabel recommends you to import the structure from the received JSON files.

[en] To import the JSON file structure:

  1. [en] Go to Data Filters and Edit your JSON filter.

  2. [en] Click Structure > Import Data Structure. Navigate to your JSON file and click Open.

    [en] After you import JSON files, the Data Preview section displays the JSON contents. The Data Preview also highlights the elements that you define as output fields.

[en] For JSON data examples, see section JSON Data.

[en] Defining JSON Fields

[en] If you define JSON fields, you make values of the selected items automatically available. Your filter definition makes such fields available for mapping to variables in actions. This allows you to extract the element values.

[en] To define JSON fields:

  1. [en] Select your element and set its Usage to Variable value.

  2. [en] The element is displayed on the structure list with bold letters, indicating that it is in use.

  3. [en] The element is used as output field name.

  4. [en] The Data Preview section highlights the values of the selected element.

    UUID-9f0f03fd-7076-59f2-c647-ba1f51e713b0.png

[en] Defining Repeatable Elements in JSON Filter

[en] If a JSON element occurs in your JSON data multiple times, it is a repeatable element. Usually, a repeatable element contains data for a single label template. Repeatable items produce multiple labels populated with relevant data.

[en] To indicate that you want to use data from all repeatable elements, and not just from the first one:

  1. [en] Select the element and define it as a Data block.

  2. [en] Enable the Repeatable element option.

UUID-8cd03b89-bc59-8a9a-0f71-cb27d3d850d8.png

[en] If the filter contains definition of elements defined as data block / repeatable element, the Use Data Filter action displays repeatable elements with nested placeholders. All actions nested below such a placeholder execute only for data blocks at this level.

警告

[en] JSON data filter with nested data block duplicates values from previous assignment area if a variable is defined in the first block but not in the second. For example, you print two labels. In the first assignment area, you defined a variable "manufacturer_serial". In the second assignment area, this variable is not present.

{
  "jobs": [
    {
      "data": [
        {
          "manufacturer_serial": "706583012001",
          "package_code": "AA792CY"
        }
      ],
      "label_filename": "serial_number_label.nlbl",
      "print_quantity": 1,
      "printer_name": "Warehouse_printer_09"
    },
    {
      "data": [
        {
          "package_code": "BE273XS"
        }
      ],
      "label_filename": "serial_number_label.nlbl",
      "print_quantity": 1,
      "printer_name": "Warehouse_09"
    }
  ]
}

[en] The expected result would be the second label without "manufacturer_serial" data. But in the actual print, the second label would contain "manufacturer_serial" value from the first label, which is 706583012001.

[en] There are three possible solutions:

  • [en] Avoid nested data blocks.

  • [en] Define variable values as empty values ("") if variables are not used in nested data blocks.

          "data": [
            {
              "manufacturer_serial": "",
              "package_code": "AA792CY"
            }
  • [en] Use conditions on actions to set variables.

  • [en] Use string manipulations when detected missing variables.

[en] Defining JSON Assignment Area

[en] JSON filter automatically identifies fields and their values in the received data. This eliminates the need for manual variable-to-field mapping.

UUID-8cd03b89-bc59-8a9a-0f71-cb27d3d850d8.png

注意

[en] Because there are no optional attributes in JSON, Automation defines Variable names and Variable values automatically.