Structured Payloads
parse · buildPayload
The text in a QR code is often more than text: a web address, a Wi-Fi network, an email, a phone number, a place. The parse operation takes such content apart into fields, buildPayload writes it from fields, and read and generate do either in the same call.
Payload types
Six kinds of content, one set of fields each
Six payload types are implemented in v11.8.0. Each has a text form that phones and scanner apps act on, and a set of fields that is the same whether you parse or build.
| Type | The content looks like | Defined by | Profiles |
|---|---|---|---|
url | https://www.example.com/path?query | RFC 3986 | web default · uriReference |
wifi | WIFI:T:WPA;S:network;P:password;; | the ZXing / Android convention | backslash default · enterprise |
email | mailto:someone@example.com?subject=... | RFC 6068 | mailto default · bareAddress |
phone | tel:+1-202-555-0143 | RFC 3966 | rfc3966 |
sms | sms:+15105550101?body=...smsto:+15105550101:message | RFC 5724, and the smsto: convention of QR generators | rfc5724 default · smsto |
geo | geo:41.8781,-87.6298 | RFC 5870 | rfc5870 |
From content to fields
parse interprets text you already have. read and extract do the same for every symbol they decode when the request says "parse": { "enabled": true }.
From fields to content
buildPayload returns the text for a set of fields. generate, measure and validate take the same fields directly and make the symbol.
unsupportedFeature, and capabilities lists each payload type with what is available for it.parse
What does this content mean?
parse examines content and reports what it is, whether it is well-formed, and its fields. It involves no image and no symbol: the content can come from a read, from a scanner, or from anywhere else.
// What does the content of this QR code mean?
Chilkat.JsonObject jsonIn = new Chilkat.JsonObject();
jsonIn.UpdateString("payload.text", "WIFI:T:WPA;S:Chilkat Guest;P:correct\\;horse;H:true;;");
Chilkat.JsonObject jsonOut = new Chilkat.JsonObject();
Chilkat.Formats fmt = new Chilkat.Formats();
bool success = fmt.QrCode("parse", jsonIn, jsonOut);
if (!success) {
Console.WriteLine(jsonOut.StringOf("errors[0].code") + ": " + jsonOut.StringOf("errors[0].message"));
return;
}
// The call succeeds whatever the content is. Test what was found.
string type = jsonOut.StringOf("type");
if (jsonOut.StringOf("classification") != "recognized") {
Console.WriteLine("plain text, or a kind of payload that is not interpreted");
} else if (jsonOut.StringOf("conformance") != "valid") {
Console.WriteLine("a malformed " + type + " payload: " + jsonOut.StringOf("findings[0].message"));
} else if (type == "wifi") {
Console.WriteLine("network " + jsonOut.StringOf("fields.ssid")
+ ", security " + jsonOut.StringOf("fields.authentication")
+ ", password " + jsonOut.StringOf("fields.password"));
}// What does the content of this QR code mean?
CkJsonObject jsonIn;
jsonIn.UpdateString("payload.text", "WIFI:T:WPA;S:Chilkat Guest;P:correct\\;horse;H:true;;");
CkJsonObject jsonOut;
CkFormats fmt;
bool success = fmt.QrCode("parse", jsonIn, jsonOut);
if (!success) {
std::cout << jsonOut.stringOf("errors[0].code") << ": " << jsonOut.stringOf("errors[0].message") << "\r\n";
return;
}
// The call succeeds whatever the content is. Test what was found.
std::string classification = jsonOut.stringOf("classification");
std::string conformance = jsonOut.stringOf("conformance");
std::string type = jsonOut.stringOf("type");
if (classification != "recognized") {
std::cout << "plain text, or a kind of payload that is not interpreted\r\n";
} else if (conformance != "valid") {
std::cout << "a malformed " << type << " payload: " << jsonOut.stringOf("findings[0].message") << "\r\n";
} else if (type == "wifi") {
std::cout << "network " << jsonOut.stringOf("fields.ssid");
std::cout << ", security " << jsonOut.stringOf("fields.authentication");
std::cout << ", password " << jsonOut.stringOf("fields.password") << "\r\n";
}import chilkat2
# What does the content of this QR code mean?
jsonIn = chilkat2.JsonObject()
jsonIn.UpdateString("payload.text", "WIFI:T:WPA;S:Chilkat Guest;P:correct\\;horse;H:true;;")
jsonOut = chilkat2.JsonObject()
fmt = chilkat2.Formats()
success = fmt.QrCode("parse", jsonIn, jsonOut)
if not success:
print(jsonOut.StringOf("errors[0].code") + ": " + jsonOut.StringOf("errors[0].message"))
exit()
# The call succeeds whatever the content is. Test what was found.
type = jsonOut.StringOf("type")
if jsonOut.StringOf("classification") != "recognized":
print("plain text, or a kind of payload that is not interpreted")
elif jsonOut.StringOf("conformance") != "valid":
print("a malformed " + type + " payload: " + jsonOut.StringOf("findings[0].message"))
elif type == "wifi":
print("network", jsonOut.StringOf("fields.ssid"),
"security", jsonOut.StringOf("fields.authentication"),
"password", jsonOut.StringOf("fields.password"))Formats, have the same methods and the same JSON requests in every supported language: C, C++, C#, VB.NET, Java, Objective-C, Swift, Python, PHP, Perl, Ruby, Node.js, Electron, React Native, Dart / Flutter, Go, Rust, Zig, Delphi, C++Builder, Free Pascal / Lazarus, Classic ASP, VB6, VBScript, FoxPro, DataFlex, PowerBuilder, Xojo, Xbase++, PureBasic, AutoIt, B4A / B4J, LabVIEW, SQL Server and Tcl. See Chilkat Downloads for Every Language.{ "payload": { "text": "WIFI:T:WPA;S:Chilkat Guest;P:correct\\;horse;H:true;;" } }{
"classification": "recognized", "type": "wifi", "profile": "backslash",
"conformance": "valid",
"fields": {
"authentication": "personal", "ssid": "Chilkat Guest", "password": "correct;horse",
"hidden": true
},
"findings": [], "source": { "representation": "text", "length": 52 },
"errors": [], "warnings": []
}The request
The groups are payload, parse and limits (accepted, without effect). The content may be at most 8192 bytes.
| Member | Values | Default | Notes |
|---|---|---|---|
payload.text | string | — | The content as text. |
payload.typepayload.base64 | "binary"base64 string | — | The content as bytes, for example bytesBase64 of a read result. |
parse.type | "auto" · "url" · "wifi" · "email" · "phone" · "sms" · "geo" | "auto" | auto recognizes the type from the content. A named type states what you expect. |
parse.preserveUnknown | bool | true | false leaves out fields.unknown[]. |
parse.includeSource | bool | false | true repeats the content in source.text or source.base64. Off by default because the content may be a credential. |
parse.strict | true | true | Parsing is strict. false (repairing malformed content) is unsupportedFeature. |
parse.url, parse.wifi,parse.email, parse.sms,parse.phone, parse.geo | object | — | Options for one type: its profile, and what url and wifi add. Allowed when parse.type is auto or names that type; next to another named type they are conflictingOptions. |
The response
| Member | Meaning |
|---|---|
classification | "recognized", "unrecognized" or "ambiguous". |
type, profile | For recognized content: what it was parsed as. |
conformance | For recognized content: "valid" (no finding of severity error), "invalid", or "unsupported" (of this type, but in a dialect that is not interpreted). |
fields | Always an object. Empty unless the content is recognized and supported. |
findings[] | Always present: { field, code, message, severity }, with severity "error" or "warning". field is the path of the member concerned (fields.to[1], fields.components.host), or empty for the content as a whole. |
candidates[] | Only when ambiguous: the types that claim the content. The six types begin differently, so this cannot occur with them. |
source | { representation, length }: "text" or "binary", and the length in bytes. |
parse returns true for any content. Text that is not a payload, and a payload that breaks the rules of its type, are completed examinations, not failures. Decide by classification and conformance. The method returns false only when the request is wrong.Recognition
With "type": "auto", content is recognized by how it begins, and by nothing else:
| Type | Begins with | Letter case |
|---|---|---|
wifi | WIFI: | exact |
email | mailto: | any |
sms | sms: or smsto: | any |
phone | tel: | any |
geo | geo: | any |
url | http:// or https:// | any |
Everything else is unrecognized: a bare address, a host name such as www.example.com, text with a leading space. Nothing is guessed.
{
"classification": "unrecognized", "fields": {}, "findings": [],
"source": { "representation": "text", "length": 15 },
"errors": [], "warnings": []
}With a type named, the content must begin as that type does; otherwise it is unrecognized and a finding says why:
{
"classification": "unrecognized", "fields": {},
"findings": [
{
"field": "", "code": "notOfExpectedType",
"message": "the content does not begin as a payload of the expected type does",
"severity": "error"
}
],
"source": { "representation": "text", "length": 23 },
"errors": [], "warnings": []
}Two profiles have no prefix to recognize and so apply only when you name the type: email / bareAddress takes the whole text as one address, and url / uriReference takes any URI reference, relative ones included. Under auto such a profile is conflictingOptions.
Valid, invalid, unsupported
Parsing is strict and literal: nothing is trimmed, repaired, normalized or guessed. Content that breaks a rule is still examined to its end. The fields that could be read are returned, and every broken rule is a finding.
{
"classification": "recognized", "type": "geo", "profile": "rfc5870",
"conformance": "invalid", "fields": { "latitude": "95.5", "longitude": "-87.6298" },
"findings": [
{
"field": "fields.latitude", "code": "outOfRange",
"message": "the latitude is beyond 90 degrees", "severity": "error"
}
],
"source": { "representation": "text", "length": 17 },
"errors": [], "warnings": []
}A warning does not make content invalid. A local telephone number without a phone-context breaks the letter of RFC 3966, but it is what most such codes hold and its meaning is not in doubt:
{
"classification": "recognized", "type": "phone", "profile": "rfc3966",
"conformance": "valid", "fields": { "number": "5551212" },
"findings": [
{
"field": "fields.phoneContext", "code": "missingPhoneContext",
"message": "a local number (one that does not begin with +) needs a phone-context parameter",
"severity": "warning"
}
],
"source": { "representation": "text", "length": 11 },
"errors": [], "warnings": []
}unsupported means the content is of the type, in a form that is not interpreted; no fields are returned. There are two cases, both of geo: a coordinate reference system other than WGS-84, and the map-search form with a ?.
{
"classification": "recognized", "type": "geo", "profile": "rfc5870",
"conformance": "unsupported", "fields": {},
"findings": [
{
"field": "", "code": "unsupportedCrs",
"message": "the coordinate reference system is not wgs84; the coordinates are not interpreted",
"severity": "warning"
}
],
"source": { "representation": "text", "length": 33 },
"errors": [], "warnings": []
}Each kind of problem is reported once per field, and at most 64 findings are listed (a 65th, findingsTruncated, says that there were more).
The six types
Fields, type by type
The fields of each type, with a real response for each. fields.unknown[], where present, holds as written whatever the grammar of the type allows and the parser does not know: other parameters, other header fields, other Wi-Fi keys.
url
| Field | Content |
|---|---|
url | The text as it stands. |
components.scheme | In lower case. |
components.userInfo | As written. Credentials in a URL get the warning userInfoPresent. |
components.host | In lower case, otherwise as written. An IP literal keeps its brackets. |
components.port | An integer. An empty port is no port. |
components.pathAbsolutecomponents.pathSegments[] | Whether the path begins with /, and its segments, percent-decoded. |
components.queryPairs[] | { name, value, hasEquals }, present when there is a ?. The query is split at & and at the first = of each part, and percent-decoded. |
components.fragment | Present when there is a #; percent-decoded. |
{
"classification": "recognized", "type": "url", "profile": "web", "conformance": "valid",
"fields": {
"url": "https://www.example.com:8443/docs/qr%20codes/index.html?lang=en&q=a+b&flag#top",
"components": {
"scheme": "https", "host": "www.example.com", "port": 8443, "pathAbsolute": true,
"pathSegments": [ "docs", "qr codes", "index.html" ],
"queryPairs": [
{ "name": "lang", "value": "en", "hasEquals": true },
{ "name": "q", "value": "a+b", "hasEquals": true },
{ "name": "flag", "value": "", "hasEquals": false }
],
"fragment": "top"
}
},
"findings": [], "source": { "representation": "text", "length": 78 },
"errors": [], "warnings": []
}Nothing is normalized: no dot-segments are removed, no default port is added or dropped, and the URL itself is returned untouched. Profile web requires an absolute http or https URL with a host. A + in a query is a plus sign unless you ask for the HTML-form reading with "parse": { "url": { "queryInterpretation": "formUtf8" } }, under which ?q=a+b gives the value a b. Errors: invalidCharacter, nonAsciiCharacter, invalidPercentEscape, missingHost, invalidHost, invalidPort, invalidScheme.
wifi
| Field | Content |
|---|---|
authentication | "open" (T absent, empty or nopass), "wep", "personal" (T is WPA, WPA2, WPA3 or SAE) or "enterprise" (WPA-EAP, WPA2-EAP, WPA3-EAP, EAP). |
ssid or ssidBase64 | The exact bytes of S, with the escapes removed: as text, or as base64 when they are not text. |
password or passwordBase64 | The exact bytes of P. |
hidden | A boolean, present only when H is. |
enterprise | With profile enterprise: eapMethod (E), phase2Method (PH2), identity (I), anonymousIdentity (A). Under the default profile these keys go to unknown[]. |
The fields may be in any order. In a value, a backslash escapes \ ; , : and ". Nothing is trimmed, unquoted or taken as hexadecimal. A password is required unless the network is open, and an SSID may be at most 32 bytes. A payload that lacks the final ;; gets the warning missingTerminator and stays valid, because some generators omit it. Errors: malformedField, duplicateField, invalidEscape, unsupportedAuthentication, missingSsid, ssidTooLong, missingPassword, unexpectedPassword, invalidHidden, trailingData.
To keep the password out of the response, for example when logging what was scanned, set includeSecret to false. The password is then left out of fields; it is of course still in the content you passed in.
{ "payload": { "text": "WIFI:T:WPA;S:Chilkat Guest;P:correct\\;horse;;" },
"parse": { "wifi": { "includeSecret": false } } }{
"classification": "recognized", "type": "wifi", "profile": "backslash",
"conformance": "valid",
"fields": {
"authentication": "personal", "ssid": "Chilkat Guest", "passwordMasked": true
},
"findings": [], "source": { "representation": "text", "length": 45 },
"errors": [], "warnings": []
}| Field | Content |
|---|---|
to[], cc[], bcc[] | Addresses, percent-decoded. to, cc and bcc header fields add to them. |
subject, body | Percent-decoded UTF-8. Line breaks in a body are returned as written. |
The content parsed below is mailto:support@example.com,sales@example.com?cc=boss@example.com&subject=QR%20order&body=Line%201%0D%0ALine%202.
{
"classification": "recognized", "type": "email", "profile": "mailto",
"conformance": "valid",
"fields": {
"to": [ "support@example.com", "sales@example.com" ], "cc": [ "boss@example.com" ],
"subject": "QR order", "body": "Line 1\r\nLine 2"
},
"findings": [], "source": { "representation": "text", "length": 111 },
"errors": [], "warnings": []
}mailto: alone is valid. Internationalized addresses are accepted. An address that is not valid is still returned in its place, with a finding. Errors: emptyAddress, invalidAddress, malformedField, duplicateField (two subjects, two bodies), fragmentNotAllowed, invalidUtf8, controlCharacter (a line break in a subject), and the three character errors of url.
phone
| Field | Content |
|---|---|
number | As written, with its + and its visual separators. |
extension | The ext parameter. |
isdnSubaddress | The isub parameter, percent-decoded. |
phoneContext | The phone-context parameter of a local number. |
{
"classification": "recognized", "type": "phone", "profile": "rfc3966",
"conformance": "valid", "fields": { "number": "+1-202-555-0143", "extension": "77" },
"findings": [], "source": { "representation": "text", "length": 26 },
"errors": [], "warnings": []
}Nothing is normalized: no 00 becomes +, and no country or length rule is applied. Errors: invalidNumber, invalidPhoneContext, invalidExtension, conflictingParameters (ext and isub together), malformedParameter, duplicateField.
sms
| Field | Content |
|---|---|
recipients[] | { number, phoneContext }: one entry per recipient. |
body | The message. Absent and empty are different. |
{
"classification": "recognized", "type": "sms", "profile": "rfc5724",
"conformance": "valid",
"fields": {
"recipients": [ { "number": "+15105550101" }, { "number": "+15105550102" } ],
"body": "hello there"
},
"findings": [], "source": { "representation": "text", "length": 48 },
"errors": [], "warnings": []
}{
"classification": "recognized", "type": "sms", "profile": "smsto", "conformance": "valid",
"fields": { "recipients": [ { "number": "+15105550101" } ], "body": "Call me back" },
"findings": [], "source": { "representation": "text", "length": 31 },
"errors": [], "warnings": []
}The profile is taken from the content: sms: is rfc5724, and smsto: is the smsto convention many QR generators write, smsto:number:message, with one recipient and nothing percent-encoded. Errors: missingRecipient, invalidNumber, invalidPhoneContext, malformedParameter, malformedField, duplicateField, invalidUtf8.
geo
| Field | Content |
|---|---|
latitude, longitude | Decimal strings, exactly as written. |
altitudeMeters | The third coordinate, when there is one. |
uncertaintyMeters | The u parameter. |
{
"classification": "recognized", "type": "geo", "profile": "rfc5870",
"conformance": "valid",
"fields": {
"latitude": "41.8781", "longitude": "-87.6298", "altitudeMeters": "181",
"uncertaintyMeters": "25"
},
"findings": [], "source": { "representation": "text", "length": 29 },
"errors": [], "warnings": []
}The numbers are strings, not JSON numbers, so that no digit is lost or added and an absent value is not zero. A latitude beyond 90 or a longitude beyond 180 is outOfRange. Other errors: invalidCoordinates, invalidNumber, malformedParameter, duplicateField, parameterOrder.
read and extract
Interpret every symbol that is read
A read or extract request with "parse": { "enabled": true } interprets the content of every symbol it decodes. Each entry of results[] (or selected[]) gains parseStatus and, when the content is a payload, parsed. Nothing else in the response changes.
// Read an image and act on what each QR code means
Chilkat.JsonObject jsonIn = new Chilkat.JsonObject();
jsonIn.UpdateString("source.path", "sheet.png");
jsonIn.UpdateBool("parse.enabled", true);
Chilkat.JsonObject jsonOut = new Chilkat.JsonObject();
Chilkat.Formats fmt = new Chilkat.Formats();
if (!fmt.QrCode("read", jsonIn, jsonOut)) {
Console.WriteLine(jsonOut.StringOf("errors[0].message"));
return;
}
int n = jsonOut.SizeOfArray("results");
for (int i = 0; i < n; i++) {
jsonOut.I = i;
string status = jsonOut.StringOf("results[i].parseStatus");
if (status != "valid") {
Console.WriteLine("text (" + status + "): " + jsonOut.StringOf("results[i].text"));
continue;
}
string type = jsonOut.StringOf("results[i].parsed.type");
if (type == "url") Console.WriteLine("open " + jsonOut.StringOf("results[i].parsed.fields.url"));
else if (type == "wifi") Console.WriteLine("join " + jsonOut.StringOf("results[i].parsed.fields.ssid"));
else if (type == "phone") Console.WriteLine("call " + jsonOut.StringOf("results[i].parsed.fields.number"));
else Console.WriteLine(type + ": " + jsonOut.StringOf("results[i].text"));
}// Read an image and act on what each QR code means
CkJsonObject jsonIn;
jsonIn.UpdateString("source.path", "sheet.png");
jsonIn.UpdateBool("parse.enabled", true);
CkJsonObject jsonOut;
CkFormats fmt;
if (!fmt.QrCode("read", jsonIn, jsonOut)) {
std::cout << jsonOut.stringOf("errors[0].message") << "\r\n";
return;
}
int n = jsonOut.SizeOfArray("results");
for (int i = 0; i < n; i++) {
jsonOut.put_I(i);
std::string status = jsonOut.stringOf("results[i].parseStatus");
if (status != "valid") {
std::cout << "text (" << status << "): " << jsonOut.stringOf("results[i].text") << "\r\n";
continue;
}
std::string type = jsonOut.stringOf("results[i].parsed.type");
if (type == "url") std::cout << "open " << jsonOut.stringOf("results[i].parsed.fields.url") << "\r\n";
else if (type == "wifi") std::cout << "join " << jsonOut.stringOf("results[i].parsed.fields.ssid") << "\r\n";
else if (type == "phone") std::cout << "call " << jsonOut.stringOf("results[i].parsed.fields.number") << "\r\n";
else std::cout << type << ": " << jsonOut.stringOf("results[i].text") << "\r\n";
}# Read an image and act on what each QR code means
jsonIn = chilkat2.JsonObject()
jsonIn.UpdateString("source.path", "sheet.png")
jsonIn.UpdateBool("parse.enabled", True)
jsonOut = chilkat2.JsonObject()
fmt = chilkat2.Formats()
if not fmt.QrCode("read", jsonIn, jsonOut):
print(jsonOut.StringOf("errors[0].message"))
exit()
n = jsonOut.SizeOfArray("results")
for i in range(n):
jsonOut.I = i
status = jsonOut.StringOf("results[i].parseStatus")
if status != "valid":
print("text (" + status + "):", jsonOut.StringOf("results[i].text"))
continue
type = jsonOut.StringOf("results[i].parsed.type")
if type == "url":
print("open", jsonOut.StringOf("results[i].parsed.fields.url"))
elif type == "wifi":
print("join", jsonOut.StringOf("results[i].parsed.fields.ssid"))
elif type == "phone":
print("call", jsonOut.StringOf("results[i].parsed.fields.number"))
else:
print(type + ":", jsonOut.StringOf("results[i].text"))
{ "source": { "path": "sheet.png" },
"parse": { "enabled": true, "wifi": { "includeSecret": false } } }[
{
"id": 0, "text": "https://www.chilkatsoft.com", "parseStatus": "valid",
"parsed": {
"type": "url", "profile": "web",
"fields": {
"url": "https://www.chilkatsoft.com",
"components": {
"scheme": "https", "host": "www.chilkatsoft.com", "pathAbsolute": false
}
},
"findings": []
}
},
{
"id": 1, "text": "WIFI:T:WPA;S:Chilkat Guest;P:correct\\;horse;;",
"parseStatus": "valid",
"parsed": {
"type": "wifi", "profile": "backslash",
"fields": {
"authentication": "personal", "ssid": "Chilkat Guest", "passwordMasked": true
},
"findings": []
}
},
{ "id": 2, "text": "INVERTED: light on dark", "parseStatus": "unrecognized" },
{
"id": 3, "text": "tel:+1-202-555-0143", "parseStatus": "valid",
"parsed": {
"type": "phone", "profile": "rfc3966", "fields": { "number": "+1-202-555-0143" },
"findings": []
}
}
]parseStatus | Meaning | parsed |
|---|---|---|
"valid" | A payload of one of the six types, without errors. | present |
"invalid" | A payload that breaks rules of its type. | present, with the findings |
"unsupported" | A payload in a form that is not interpreted. | present, with empty fields |
"unrecognized" | Not a payload of the six types: plain text, for example. | absent |
"partial" | One symbol of a structured-append set. A fragment is not interpreted on its own. | absent |
parsed is { type, profile, fields, findings[] }. The parse group takes the same members as for the parse operation, except includeSource (the result has the content). Under "type": "auto" you may give the options of several types, and each applies to the symbols of its type — as includeSecret does above.
- What is interpreted is the symbol's
textwhen it has one, and its bytes otherwise. - For a structured-append set, the parts are
partialand the complete message is interpreted: its entry inassemblies[]getsparseStatusandparsed. detectdoes not decode, and refusesparse.
buildPayload
Write content from fields
buildPayload is the reverse of parse: it writes the content for a set of fields. The escaping and percent-encoding each format demands is done for you, and the result is checked before it is returned.
// Write a Wi-Fi payload from its fields ...
Chilkat.JsonObject jsonIn = new Chilkat.JsonObject();
jsonIn.UpdateString("payload.type", "wifi");
jsonIn.UpdateString("payload.fields.authentication", "personal");
jsonIn.UpdateString("payload.fields.ssid", "Chilkat Guest");
jsonIn.UpdateString("payload.fields.password", "correct;horse");
Chilkat.JsonObject jsonOut = new Chilkat.JsonObject();
Chilkat.Formats fmt = new Chilkat.Formats();
if (!fmt.QrCode("buildPayload", jsonIn, jsonOut)) {
// errors[0].path names the field, for example /payload/fields/password
Console.WriteLine(jsonOut.StringOf("errors[0].path") + ": " + jsonOut.StringOf("errors[0].message"));
return;
}
Console.WriteLine(jsonOut.StringOf("payload.text")); // WIFI:T:WPA;S:Chilkat Guest;P:correct\;horse;;
// ... or make the QR code from the same fields in one step
jsonIn.UpdateInt("render.moduleSize", 5);
jsonIn.UpdateString("output.path", "wifi.png");
jsonIn.UpdateBool("output.overwrite", true);
bool success = fmt.QrCode("generate", jsonIn, jsonOut);// Write a Wi-Fi payload from its fields ...
CkJsonObject jsonIn;
jsonIn.UpdateString("payload.type", "wifi");
jsonIn.UpdateString("payload.fields.authentication", "personal");
jsonIn.UpdateString("payload.fields.ssid", "Chilkat Guest");
jsonIn.UpdateString("payload.fields.password", "correct;horse");
CkJsonObject jsonOut;
CkFormats fmt;
if (!fmt.QrCode("buildPayload", jsonIn, jsonOut)) {
// errors[0].path names the field, for example /payload/fields/password
std::cout << jsonOut.stringOf("errors[0].path") << ": " << jsonOut.stringOf("errors[0].message") << "\r\n";
return;
}
std::cout << jsonOut.stringOf("payload.text") << "\r\n"; // WIFI:T:WPA;S:Chilkat Guest;P:correct\;horse;;
// ... or make the QR code from the same fields in one step
jsonIn.UpdateInt("render.moduleSize", 5);
jsonIn.UpdateString("output.path", "wifi.png");
jsonIn.UpdateBool("output.overwrite", true);
bool success = fmt.QrCode("generate", jsonIn, jsonOut);import chilkat2
# Write a Wi-Fi payload from its fields ...
jsonIn = chilkat2.JsonObject()
jsonIn.UpdateString("payload.type", "wifi")
jsonIn.UpdateString("payload.fields.authentication", "personal")
jsonIn.UpdateString("payload.fields.ssid", "Chilkat Guest")
jsonIn.UpdateString("payload.fields.password", "correct;horse")
jsonOut = chilkat2.JsonObject()
fmt = chilkat2.Formats()
if not fmt.QrCode("buildPayload", jsonIn, jsonOut):
# errors[0].path names the field, for example /payload/fields/password
print(jsonOut.StringOf("errors[0].path") + ": " + jsonOut.StringOf("errors[0].message"))
exit()
print(jsonOut.StringOf("payload.text")) # WIFI:T:WPA;S:Chilkat Guest;P:correct\;horse;;
# ... or make the QR code from the same fields in one step
jsonIn.UpdateInt("render.moduleSize", 5)
jsonIn.UpdateString("output.path", "wifi.png")
jsonIn.UpdateBool("output.overwrite", True)
success = fmt.QrCode("generate", jsonIn, jsonOut)Formats, have the same methods and the same JSON requests in every supported language: C, C++, C#, VB.NET, Java, Objective-C, Swift, Python, PHP, Perl, Ruby, Node.js, Electron, React Native, Dart / Flutter, Go, Rust, Zig, Delphi, C++Builder, Free Pascal / Lazarus, Classic ASP, VB6, VBScript, FoxPro, DataFlex, PowerBuilder, Xojo, Xbase++, PureBasic, AutoIt, B4A / B4J, LabVIEW, SQL Server and Tcl. See Chilkat Downloads for Every Language.{
"payload": {
"type": "wifi",
"fields": {
"authentication": "personal", "ssid": "Chilkat Guest", "password": "correct;horse",
"hidden": true
}
}
}{
"type": "wifi", "profile": "backslash",
"payload": {
"type": "text", "text": "WIFI:T:WPA;S:Chilkat Guest;P:correct\\;horse;H:true;;"
},
"byteCount": 52, "findings": [],
"errors": [], "warnings": []
}| Member | Values | Notes |
|---|---|---|
payload.type | "url" · "wifi" · "email" · "phone" · "sms" · "geo" | Required. |
payload.profile | a profile of the type | Optional. The default is the first profile of the type. |
payload.fields | object | Required: the fields of the type, as parse returns them. |
In the response, payload is an ordinary payload of generate: { "type": "text", "text": "..." }, or { "type": "binary", "base64": "..." } when the bytes are not text (an SSID given as ssidBase64, for example). byteCount is its length, and findings[] holds the warnings the parser has for what was written.
What is written
| Type | Fields | Example of what is built |
|---|---|---|
url | url (the URL as text, written as it is) or components: scheme, userInfo, host, port, pathAbsolute, pathSegments[], queryPairs[], fragment | https://www.example.com/docs/qr%20codes/index.html?q=a%2Bb%20%26%20c#top |
wifi | authentication (required), ssid or ssidBase64, password or passwordBase64, hidden; with profile enterprise, enterprise | WIFI:T:WPA;S:Chilkat Guest;P:correct\;horse;H:true;; |
email | to[], cc[], bcc[], subject, body | mailto:support@example.com?cc=boss@example.com&subject=QR%20order&body=Line%201%0D%0ALine%202%20%26%20more |
phone | number (required), extension, isdnSubaddress, phoneContext | tel:+1-202-555-0143;ext=77 |
sms | recipients[] (number, phoneContext), body | sms:+15105550101?body=hello%20theresmsto:+15105550101:Call me back (profile smsto) |
geo | latitude, longitude (required), altitudeMeters, uncertaintyMeters: decimal strings | geo:41.8781,-87.6298;u=25 |
The URL above was built from the path segments docs, qr codes, index.html and the query value a+b & c: spaces, + and & were percent-encoded. The email body held a line break and an ampersand. Wi-Fi personal is written as T:WPA, enterprise as T:WPA2-EAP, and open as T:nopass.
How a request is checked
What is built is always content that parse calls valid. Three checks see to that, and each failure names the field by its JSON Pointer:
| Code | Path | Message | For these fields |
|---|---|---|---|
unknownOption | /payload/fields/bogus | unknown option | { "latitude": "1", "longitude": "2", "bogus": 1 } |
missingOption | /payload/fields/longitude | this field is required | { "latitude": "41.8781" } |
wrongType | /payload/fields/latitude | a string is required | { "latitude": 41.8781, "longitude": "-87.6298" } |
invalidPayload | /payload/fields/number | the number is not a telephone number as a tel URI writes it | { "number": "5551212;ext=1" } |
invalidPayload | /payload/fields/latitude | the latitude is beyond 90 degrees | { "latitude": "95.5", "longitude": "-87.6298" } |
invalidPayload | /payload/fields/password | there is no password (P) for a network with authentication | { "authentication": "personal", "ssid": "home" } |
conflictingOptions | /payload/fields/components | give url or components, not both: which of them is meant cannot be told | { "url": "https://www.example.com/", "components": { "scheme": "https", "host": "www.example.com" } } |
unknownOption | /payload/fields/unknown | unknown option | { "authentication": "open", "ssid": "cafe", "unknown": [ "X:1" ] } |
- A member of
fieldsthat is unknown, missing or of the wrong type fails with the request codesunknownOption,missingOption,wrongType. - A value that is written without encoding — a telephone number, a host, the numbers of
geo— must not bring a separator of its own:"number": "5551212;ext=1"is refused rather than read as a number with an extension. - The content that was written is then parsed. Anything the parser calls an error fails the call with
invalidPayloadat the field, with the parser's message.
Parse, change, build
Because fields is what parse returns, you can parse content, change a field and build it again. Three things in a parse result are refused rather than silently dropped: unknown[] (the builder writes only what it knows), passwordMasked (there is no password to write), and a URL result as it stands, which holds both url and components — pass one of them. The numbers of geo must be strings, as parse returns them, so that the digits are written exactly as given. A payload longer than 8192 bytes is outOfRange.
generate
A QR code straight from fields
generate, measure and validate accept the same payload.type, payload.fields and payload.profile in place of payload.text. The symbol is exactly the one generated from the text buildPayload writes for those fields, and a field that is wrong fails the call in the same way.
{
"payload": {
"type": "wifi",
"fields": {
"authentication": "personal", "ssid": "Chilkat Guest", "password": "correct;horse"
}
},
"render": { "moduleSize": 5 }, "verifyReadback": true
}
The response is that of any generate; symbols[0].payloadBytes is 45, the length of the text that was built. The request above also asks for verifyReadback, so the image was read back before it was returned.
generate, measure, validate and buildPayload take a structured payload. For parse, payload.type is "text" or "binary".