Official translation unavailable. Translate this page with Google:

JSON Filter

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

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.

Note

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

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

To import the JSON file structure:

  1. Go to Data Filters and Edit your JSON filter.

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

    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.

For JSON data examples, see section JSON Data.

Defining JSON Fields

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.

To define JSON fields:

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

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

  3. The element is used as output field name.

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

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

Defining Repeatable Elements in JSON Filter

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.

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

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

  2. Enable the Repeatable element option.

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

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.

Warning

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"
    }
  ]
}

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.

There are three possible solutions:

  • Avoid nested data blocks.

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

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

  • Use string manipulations when detected missing variables.

Defining JSON Assignment Area

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

Note

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