SDK Documentation Help

Reading GS1 Data

Application Identifiers

GS1 is a global organization that sets standards for efficient and accurate supply chain management, with its most notable contribution being the development of the barcode. Founded in 1974, GS1's mission is to enhance the flow of goods and information across various industries by providing a universal system for product identification and data sharing.

A key element of GS1's standards is the use of Application Identifiers (AIs) in barcodes. These identifiers allow specific data, such as batch numbers, expiration dates, and serial numbers, to be encoded within a barcode. This capability enables precise tracking and traceability of products throughout the supply chain, improving efficiency and ensuring product safety.

Example: GS1 UDI encoded in a Data Matrix code

The Data Matrix code below encodes a GS1 Unique Device Identification (UDI) with multiple AIs.

Data Matrix code encoding a GS1 UDI

The symbology identifier is ]d2, identifying it as a GS1 Data Matrix code. The textual data contained in this code is 0108806388269617112302141728021310230214A3263-01<GS>21059<GS>240ARO4808C. The ASCII group separator is a non-printable character used to delimit variable-length AIs and represented as <GS> here.

The AIs encoded in this Data Matrix barcode are shown below.

Numeric AI

Description

Length

Data

01

GTIN

14

08806388269617

10

Lot number

variable

10230214A3263-01

11

Production date

6

230214

17

Expiration date

6

280213

21

Serial number

variable

059

240

Manufacturer-specific ID

variable

ARO4808C

Reading AIs from Scanned Barcodes

Currently STRICH does not expose the AIs in a structured way. Instead, when a GS1 barcode is read, the appropriate symbology identifier is included in the detection, along with the barcode payload, to help distinguish it from a regular barcode.

We might choose to provide this feature directly in our library, given enough interest from customers. In the meantime, we recommend you use freely available libraries such as BarcodeParser or the GS1 Digital Link Toolkit to extract the AIs from the GS1 element string.

In the following sections, we will show how to use both tools to achieve to parse the GS1 AIs into a human-readable interpretation. The full sample code is available in the gs1-ai-parsing Github repository.

Using the BarcodeParser Library to Extract GS1 AIs

Loading the BarcodeParser Library

Include the BarcodeParser library by loading it via a script tag from a CDN. the library is not available on NPM. Here we include the minified version via the jsDeliver CDN.

<!-- load BarcodeParser library via jsDeliver CDN --> <script src="https://cdn.jsdelivr.net/gh/PeterBrockfeld/BarcodeParser@HEAD/scripts/BarcodeParser.min.js"></script>

Parsing the Barcode using parseBarcode

The barcode data is parsed using the aptly named parseBarcode function. The function returns an object containing an array of parsed AIs. In the code snippet below, we assemble it into newline-separated human-readable interpretation, with each line containing the AI, the AI description, and the AI data (e.g. 10 (BATCH/LOT): 230214A3263-01).

const answer = parseBarcode(data); let hri = ''; for (let item of answer.parsedCodeItems) { hri += `${item.ai} (${item.dataTitle}): ${item.data}`; hri += '\n'; } outputElem.innerText = hri;

Loading the GS1DigitalLinkToolkit.js Library

Include the GS1DigitalLinkToolkit.js library by bundling it or by loading it via a script from a CDN. The library is not available on NPM. Here we load the latest version in the GitHub repository via the jsDeliver CDN.

<!-- load GS1 DLT via jsDeliver CDN --> <script src="https://cdn.jsdelivr.net/gh/gs1/GS1DigitalLinkToolkit.js@HEAD/js/GS1DigitalLinkToolkit.js"></script>

Parsing the Barcode using extractFromGS1elementStrings

Instantiate the GS1DigitalLinkToolkit class and call the extractFromGS1elementStrings method, passing the barcode data.

const dlt = new GS1DigitalLinkToolkit(); const answer = dlt.extractFromGS1elementStrings(data);

The result of the method is a dictionary containing the AIs and the associated data. For the sample input 0108806388269617112302141728021310230214A3263-0121059240ARO4808C, the output is the following dictionary:

{ "10": "230214A3263-01", "11":"230214", "17":"280213", "21":"059", "240":"ARO4808C", "01":"08806388269617" }
Last modified: 11 November 2024