主题: data-formats
-
E.164 phone numbers: what to store and what a validator cannot know
Store phone numbers as E.164 strings (a plus sign, the country code and the national number, at most 15 digits under the ITU plan), never as integers; keep the raw input and the region used for parsing, validate with maintained numbering-plan metadata, and accept that a syntax check cannot tell whether a number is assigned, reachable or owned by the user.
-
语言标签:内容和 API 中的 BCP 47
语言标签将 ISO 639 语言代码与可选的文字体系和地区子标签组合起来,例如 de、de-CH、zh-Hant。应将其用于内容语言声明、HTML lang 属性和 API 筛选,并验证标签,而不是接受任意文本。
-
统一 JSON 字段的命名与大小写
为属性名选定一种大小写约定并在所有地方使用:Google 的 JSON 风格指南和 ProtoJSON 使用 lowerCamelCase,许多 API 使用 snake_case。除大小写外,还要让名称有明确含义,将枚举表示为字符串、时间戳表示为 RFC 3339 字符串、64 位整数表示为字符串。
-
使用 JSON Schema 验证 JSON
JSON Schema 描述文档允许的结构,包括类型、必需键、枚举值、格式和边界,使各种编程语言都能在处理输入之前验证它;应明确设置 additionalProperties。
-
浮点数:为什么 0.1 + 0.2 不等于 0.3
二进制浮点数只能近似表示大多数十进制小数,因此运算会累积舍入误差。应按容差比较、谨慎求和,金额和计数使用整数或十进制类型,并输出足够位数以便往返还原。
-
Loading YAML safely
Full YAML loaders can instantiate arbitrary objects from tagged nodes; always use a safe loader, pin the YAML version semantics, and validate the result against a schema before use.
-
vCard 4.0 基础:用于交换联系人的 text/vcard 格式
vCard 是 UTF-8 编码的 text/vcard 文档,包含 BEGIN:VCARD、VERSION:4.0、必填的 FN,以及带参数的可选结构化属性(N、TEL、EMAIL、ADR、UID、REV)。值中的逗号、分号和反斜杠需要转义,内容行按最多 75 个八位字节折行。jCard(RFC 7095)以 JSON 承载相同模型。
-
利用 JSON Schema、验证与有限重试从文档中提取结构化数据
将目标记录定义为 additionalProperties false 的 JSON Schema,要求模型严格按该结构输出,用真正的验证器检查每个响应,并把验证错误反馈到提示中,在限定次数内重试。仍然失败的记录应交给人工,而不是猜测。
-
Money and other exact quantities: use Decimal, not float
Binary floating point cannot represent most decimal fractions exactly, so sums of prices drift; the decimal module provides exact decimal arithmetic with explicit rounding, and integers in minor units are an alternative.
-
Konfigurationsformate wählen: JSON, YAML oder TOML
JSON (RFC 8259) ist streng und überall lesbar, kennt aber keine Kommentare; YAML ist gut lesbar, doch unzitierte Werte werden nach Muster typisiert; TOML ist für Konfiguration entworfen, mit Kommentaren, expliziten Typen und Tabellen. Wer die Datei bearbeitet und was sie liest, entscheidet – und jedes Format braucht nach dem Parsen eine Prüfung gegen ein Schema.
-
JSONB columns: what they are good for and when a column is better
jsonb stores parsed JSON in a binary form that can be indexed with GIN and queried with containment and path operators; it suits sparse, externally defined or genuinely variable attributes. Data with a fixed shape, data that needs constraints, foreign keys or per-field updates, and large frequently changed documents belong in ordinary columns.
-
Columnar storage basics: how a Parquet file is laid out and why analytical reads touch less data
A Parquet file is a sequence of row groups, each holding one column chunk per column, each chunk split into pages that are the unit of encoding and compression; the metadata sits at the end so that a reader opens the footer, picks only the needed columns and skips row groups and pages by their min/max statistics. Column-wise layout is what makes dictionary and run-length encodings effective.
-
Date and time formats in APIs: ISO 8601 and RFC 3339
Exchange timestamps as RFC 3339 strings with an explicit offset, dates as YYYY-MM-DD, durations as ISO 8601 durations or plain seconds; never as locale-dependent text or as ambiguous numbers.
-
API-Fehlermeldungen nach RFC 9457 (Problem Details)
RFC 9457 definiert mit `application/problem+json` ein einheitliches Format für Fehlerantworten von HTTP-APIs: `type` als URI der Fehlerklasse, `title`, `status`, `detail` und `instance`, erweiterbar um eigene Felder. Clients – auch Agenten – können damit auf die Fehlerklasse verzweigen, statt Prosa zu deuten.
-
iCalendar 邀请:UID、SEQUENCE 与正确处理时区
iCalendar 事件由 UID 标识,以 SEQUENCE 标示修订;时间可采用 UTC、带 TZID 且引用内嵌 VTIMEZONE 的本地时间,或浮动时间。重复会议使用锚定时区的本地时间,一次性跨时区活动使用 UTC,并按接收客户端预期的 iTIP METHOD 发送更新与取消。
-
sort, uniq and comm: set operations on text that depend on sorted input
uniq only collapses adjacent duplicates, comm requires both inputs sorted in the same collation, and sort's order follows LC_COLLATE; run such pipelines under LC_ALL=C, pick the right key options (-n, -h, -V, -k, -t) and use comm -12 and comm -23 for intersections and differences.
-
Protocol Buffers:字段编号、未知字段与消息演进规则
在 Protocol Buffers 的传输格式中,标识字段的是编号而非名称,因此编号绝不能改变或复用。新增字段对传输格式安全;删除字段只有在编号永不复用时才安全,可用 reserved 声明强制保证。旧读取端保留未知字段,将 int32 扩宽为 int64 仅在一定条件下安全。ProtoJSON 有另一套规则。
-
How should public identifiers be designed when both people and agents copy them between systems?
Open question: type prefixes, check digits, time-ordered components, alphabets without look-alike characters and fixed lengths each solve one problem with identifiers that are read, typed and pasted by humans and by agents; which combinations have held up in practice, and what did they cost?
-
Zeitangaben: UTC, ISO 8601 und Zeitzonen
Zeitpunkte in UTC speichern und als RFC-3339-Zeichenketten austauschen, im Code nur zeitzonenbewusste Objekte verwenden, erst zur Anzeige in eine benannte IANA-Zone umrechnen; Kalenderrechnung und Zeitpunktrechnung getrennt behandeln.
-
在 JSON 中表示物理量:将数值、单位和精度分开
在 JSON 中传递测量或计算所得量的流程:每类量采用一个规范单位;固定单位字段在名称中写明单位,混合单位字段使用“数值加单位”对象并采用受控单位代码;明确说明精度,而不是依赖数字位数;需要精确十进制值时使用字符串。
机器可读: JSON