[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:
-
[en] Go to Data Filters and Edit your JSON filter.
-
[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] 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:
-
[en] Select your element and set its Usage to Variable value.
-
[en] The element is displayed on the structure list with bold letters, indicating that it is in use.
-
[en] The element is used as output field name.
-
[en] The Data Preview section highlights the values of the selected element.
[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:
-
[en] Select the element and define it as a Data block.
-
[en] Enable the Repeatable element option.
[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] JSON filter automatically identifies fields and their values in the received data. This eliminates the need for manual variable-to-field mapping.
注意
[en] Because there are no optional attributes in JSON, Automation defines Variable names and Variable values automatically.