Gs1DigitalLink
public static class Gs1DigitalLinkGS1 Digital Link URIs (GS1 Digital Link Standard: URI Syntax, release 1.7.0): build them from GS1 element strings, parse and validate them, and convert between both forms.
Structure: https://{domain}[/{custom path}]/{primary key AI}/{value}[/{qualifier AI}/{value}…][?{AI}={value}&…]. The primary key (GTIN, SSCC, GLN …) and its key qualifiers (e.g. /22 CPV, /10 batch/lot, /21 serial, in this order) form the path; all other AIs are data attributes in the query string. The AI tables (primary keys, qualifier sequences, permitted data attributes) follow the ABNF of the standard and the GS1 Barcode Syntax Dictionary; value formats and check digits are validated with Gs1.
Issue codes: scheme, characters, host, noPath, trailingSlash, noPrimaryKey, convenienceAlpha, pathPairs, unknownAi, emptyValue, mustPercentEncode, percentEncoding, notQualifier, qualifierOrder, qualifierRequired, gtinLength, queryKeyNumeric, belongsInPath, notDataAttribute, duplicateAi, aiValue, exclusiveAis; warnings: http, requisiteAis, doubleQuote, zeroSuppressedGtin, compressedLegacy, compressedEpc, compressedUndecodable.
Try it online on zplCloud.com: Sunrise 2027 Migration
Fields & Constants
| Field | Type | Description |
|---|---|---|
const DefaultStem = "https://id.gs1.org" | string | Default domain (stem) of canonical URIs: https://id.gs1.org. |
Methods
| Method Signature | Returns | Description |
|---|---|---|
static # Build(string elementString, string? stem = default) | string | Builds an uncompressed GS1 Digital Link URI from element strings in bracketed form "(01)09520123456788(10)ABC" or raw form (FNC1 / GS U+001D separated, optional symbology identifier "]C1", "]d2", "]Q3"). elementString: The GS1 data. · stem: Domain and optional path prefix, e.g. "https://brand.example.com" or "https://example.com/products" (default Gs1DigitalLink.DefaultStem; a trailing slash is removed). Throws ArgumentException: The data or the stem is invalid (the message lists every problem). |
static # Build(IEnumerable<Gs1Element> elements, string? stem = default) | string | Builds an uncompressed GS1 Digital Link URI from AI elements. The first primary key AI becomes the path root; the longest key qualifier sequence present in the data is put in the path in its mandatory order; the remaining AIs become data attributes in the query string in lexical order of the AI (the canonical order). Every value is validated (format, check digit, character set) and percent-encoded (every character except A–Z a–z 0–9 - . _ ~). Throws ArgumentException: The data or the stem is invalid (the message lists every problem). |
static # Decompress(string compressedUri) | string | Decodes a URI compressed with the legacy algorithm of the GS1 Digital Link Standard 1.1/1.2 (binary AI encoding, base64url) into its uncompressed form on the same stem. That algorithm is superseded (URI Syntax 1.7.0 §6.1.2: not maintained, not approved for open supply chains) and retail POS requires uncompressed URIs, so this exists to read old labels; zplCore does not compress. The EPC-binary compression ('eh'/'ex' flags) is not supported. Throws ArgumentException: Not a decodable legacy compressed URI. |
static # IsDataAttribute(string ai) | bool | True when the AI may appear as a data attribute in the query string. |
static # IsPrimaryKey(string ai) | bool | True when the AI is a primary key of a GS1 Digital Link URI (01, 00, 414, 8004 …). |
static # KeyQualifiers(string primaryKey) | IReadOnlyList<IReadOnlyList<string>> | Key qualifier sequences of a primary key, e.g. for "01": [["22","10","21"], ["235"]] (each list in path order, each qualifier optional except (8020) after (415)); empty when the key has no qualifiers or is not a key. |
static # NormalizeGtin(string gtin) | string | A GTIN-8, GTIN-12, GTIN-13 or GTIN-14 as the 14-digit value of AI (01) (leading zeros added, check digit verified). Throws ArgumentException: Not 8, 12, 13 or 14 digits, or a wrong check digit. |
static # Parse(string uri, Gs1DigitalLinkParseOptions? options = default) | Gs1DigitalLinkResult | Parses and validates a GS1 Digital Link URI against URI Syntax 1.7.0: scheme, host, custom path, primary key, key qualifier sequence and order, 14-digit GTIN, percent-encoding, data attributes (permitted AIs, AIs that belong in the path, all-numeric extension keys), duplicate AIs, AI value formats and check digits, invalid AI pairs. Missing requisite AIs (GenSpecs §4.13.2) are warnings, because another carrier on the item may hold them. Legacy compressed URIs are decoded (see Gs1DigitalLinkParseOptions.DecodeLegacyCompression). |
static # PercentEncode(string value) | string | Percent-encodes every character except the RFC 3986 unreserved set (A–Z a–z 0–9 - . _ ~), upper-case hex, UTF-8. This covers every character URI Syntax §4.1 requires to be encoded (# / % & + , ! ( ) * ' : ; < = > ?). |
static # ToElementString(string uri, bool bracketed = true) | string | Element string of a GS1 Digital Link URI, bracketed "(01)…(17)…(10)…" or raw (GS separators). Throws ArgumentException: The URI is not a valid GS1 Digital Link URI (the message lists the errors). |
static # TryBuild(IEnumerable<Gs1Element> elements, string stem, out string uri, out IReadOnlyList<Gs1DigitalLinkIssue> errors) | bool | Like Gs1DigitalLink.Build but returns the problems instead of throwing. |

