โฑ๏ธ Estimated read: 3 min
|
|
Format Comparison
| Format | Human-Readable | Schema | Size vs JSON | Parse Speed |
|---|
| JSON | Yes | None | Baseline | Moderate |
| YAML | Yes | None (implicit) | Larger | Slow |
| TOML | Yes | None (explicit) | Larger | Moderate |
| Protobuf | No | Required | ~95% smaller | Fast |
| Avro | No | Required (embedded) | Small | Fast |
| MessagePack | No | None | ~4โ63% smaller | Fast |
| CBOR | No | None (tags) | ~19% smaller | Fast |
| FlatBuffers | No | Required | Small | Zero-copy |
When to Use Which
| Scenario | Format | Reason |
|---|
| API responses | JSON | Universal, safe, debuggable |
| CI/CD, K8s | YAML | Ecosystem standard |
| App config (Rust/Python) | TOML | Explicit typing, comments |
| Internal high-rate RPC | Protobuf | Compact, field numbers |
| Data pipelines | Avro | Schema evolution, dynamic typing |
| IoT, COSE, WebAuthn | CBOR | Byte strings, tags, determinism |
| Browser + JSON-like | MessagePack | No schema, fast |
| Zero-copy reads | FlatBuffers | No parse step |
Human-Readable vs Binary
| Aspect | Text (JSON/YAML/TOML) | Binary (Protobuf/MessagePack) |
|---|
| Debuggable | Yes, any tool | Needs schema-aware tooling |
| Size | Larger | Smaller |
| Parse cost | Delimiter scan + convert | Direct read |
| Compression effect | Shrinks size, not parse | N/A |
| Decision driver | Low volume, human consumer | High volume, machine consumer |
YAML Cheatsheet
| Element | Syntax |
|---|
| Mapping | key: value |
| Sequence | - item |
| Anchor | &name |
| Alias | *name |
| Merge | <<: *name |
| Literal block | | (newlines kept) |
| Folded block | > (newlines folded) |
| Chomping | |- strip, |+ keep |
| Document start | --- |
| Document end | ... |
YAML Security
| Risk | Mitigation |
|---|
Code execution (yaml.load) | yaml.safe_load |
| Billion laughs | Alias limit (128), expansion budget |
| Alias expansion DoS | Size cap, depth limit |
| Custom tag RCE | Register on SafeLoader only |
TOML Cheatsheet
| Element | Syntax |
|---|
| Key-value | key = value |
| Table | [table] |
| Nested table | [parent.child] |
| Array of tables | [[name]] |
| Inline table | { x = 1, y = 2 } |
| Array | [1, 2, 3] |
| Literal string | 'C:\path' |
| Multi-line | """...""" |
| Comment | # text |
TOML Data Types
| Type | Example |
|---|
| Integer | 42, 0xFF, 0o755, 0b1010 |
| Float | 3.14, 5e+22, inf, nan |
| Boolean | true, false |
| Offset date-time | 2026-05-05T10:00:00Z |
| Local date-time | 2026-05-05T10:00:00 |
| Local date | 2026-05-05 |
| Local time | 10:00:00 |
Protobuf Cheatsheet
| Element | Syntax |
|---|
| Message | message User { string id = 1; } |
| Field number range | 1โ15 (1 byte), 16โ2047 (2 bytes) |
| Negative-efficient | sint32/sint64 (ZigZag) |
| Repeated | repeated string tags = 5; |
| Optional | optional string nick = 3; |
| Reserved | reserved 5, "old_field"; |
| Tag formula | (fieldNumber << 3) | wireType |
Protobuf Compatibility
| Change | Classification |
|---|
| Add field (new number) | Safe |
Add optional to scalar | Wire-safe, code-breaking |
| Remove field | Safe if reserved |
| Renumber field | Breaking |
| Reuse deleted number | Breaking |
Zod Cheatsheet
| Schema | Type |
|---|
z.string() | string |
z.number() | number |
z.boolean() | boolean |
z.date() | Date |
z.email() (v4) | string |
z.uuid() (v4) | string |
z.array(S) | T[] |
z.tuple([A, B]) | [A, B] |
z.object({...}) | {...} |
z.enum([...]) | Literal union |
z.discriminatedUnion("type", [...]) | Tagged union |
Zod Parse Methods
| Method | Returns | Use |
|---|
.parse(data) | Typed output | Throws on failure |
.safeParse(data) | Union | Never throws |
.parseAsync(data) | Promise | Async schema |
.safeParseAsync(data) | Promise of union | Async + safe |
Zod Type Inference
| Utility | Returns |
|---|
z.infer<typeof S> | Output type |
z.input<typeof S> | Input type (pre-transform) |
z.output<typeof S> | Output type |
Zod Refine vs Transform
| Method | Purpose |
|---|
.refine(fn) | Custom validation (boolean) |
.superRefine(fn) | Multiple issues via ctx |
.transform(fn) | Input โ output conversion |
.pipe(schema) | Stage schemas |
Zod Error Customization (v4)
| v3 | v4 |
|---|
message | error |
invalid_type_error | error function |
required_error | error function |
errorMap | error function |
Zod + React Hook Form
| Element | Code |
|---|
| Install | react-hook-form zod @hookform/resolvers |
| Resolver | resolver: zodResolver(Schema) |
| Form noValidate | <form noValidate> |
| Field array key | field.id |
| Cross-field | register("a", { deps: "b" }) |
| Transforms | useForm<z.input<>, unknown, z.infer<>> |
Security Rules
| Rule | Detail |
|---|
| YAML | safe_load, alias limits |
| JSON | Safe by default |
| TOML | Safe (no executable constructs) |
| Deserialization | No native formats on untrusted input |
| Protobuf | Field numbers permanent |
| Canonical serialization | Sign canonical bytes, not original |
Streaming Formats
| Format | Separator | Use |
|---|
| JSON Lines | \n | Logs, data export |
| NDJSON | \n | Same, current name |
| JSON Text Sequence | 0x1E (RFC 7464) | Newlines in records |
Quick How-To Guides & Fast FixesNeed a quick fix or step-by-step solution? Browse our fast answers on HowTo.KandZ.me:
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!