| | |

Serialization 18 ๐Ÿ“„ Cheatsheet

โฑ๏ธ Estimated read: 3 min | |

Format Comparison

FormatHuman-ReadableSchemaSize vs JSONParse Speed
JSONYesNoneBaselineModerate
YAMLYesNone (implicit)LargerSlow
TOMLYesNone (explicit)LargerModerate
ProtobufNoRequired~95% smallerFast
AvroNoRequired (embedded)SmallFast
MessagePackNoNone~4โ€“63% smallerFast
CBORNoNone (tags)~19% smallerFast
FlatBuffersNoRequiredSmallZero-copy

When to Use Which

ScenarioFormatReason
API responsesJSONUniversal, safe, debuggable
CI/CD, K8sYAMLEcosystem standard
App config (Rust/Python)TOMLExplicit typing, comments
Internal high-rate RPCProtobufCompact, field numbers
Data pipelinesAvroSchema evolution, dynamic typing
IoT, COSE, WebAuthnCBORByte strings, tags, determinism
Browser + JSON-likeMessagePackNo schema, fast
Zero-copy readsFlatBuffersNo parse step

Human-Readable vs Binary

AspectText (JSON/YAML/TOML)Binary (Protobuf/MessagePack)
DebuggableYes, any toolNeeds schema-aware tooling
SizeLargerSmaller
Parse costDelimiter scan + convertDirect read
Compression effectShrinks size, not parseN/A
Decision driverLow volume, human consumerHigh volume, machine consumer

YAML Cheatsheet

ElementSyntax
Mappingkey: 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

RiskMitigation
Code execution (yaml.load)yaml.safe_load
Billion laughsAlias limit (128), expansion budget
Alias expansion DoSSize cap, depth limit
Custom tag RCERegister on SafeLoader only

TOML Cheatsheet

ElementSyntax
Key-valuekey = 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

TypeExample
Integer42, 0xFF, 0o755, 0b1010
Float3.14, 5e+22, inf, nan
Booleantrue, false
Offset date-time2026-05-05T10:00:00Z
Local date-time2026-05-05T10:00:00
Local date2026-05-05
Local time10:00:00

Protobuf Cheatsheet

ElementSyntax
Messagemessage User { string id = 1; }
Field number range1โ€“15 (1 byte), 16โ€“2047 (2 bytes)
Negative-efficientsint32/sint64 (ZigZag)
Repeatedrepeated string tags = 5;
Optionaloptional string nick = 3;
Reservedreserved 5, "old_field";
Tag formula(fieldNumber << 3) | wireType

Protobuf Compatibility

ChangeClassification
Add field (new number)Safe
Add optional to scalarWire-safe, code-breaking
Remove fieldSafe if reserved
Renumber fieldBreaking
Reuse deleted numberBreaking

Zod Cheatsheet

SchemaType
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

MethodReturnsUse
.parse(data)Typed outputThrows on failure
.safeParse(data)UnionNever throws
.parseAsync(data)PromiseAsync schema
.safeParseAsync(data)Promise of unionAsync + safe

Zod Type Inference

UtilityReturns
z.infer<typeof S>Output type
z.input<typeof S>Input type (pre-transform)
z.output<typeof S>Output type

Zod Refine vs Transform

MethodPurpose
.refine(fn)Custom validation (boolean)
.superRefine(fn)Multiple issues via ctx
.transform(fn)Input โ†’ output conversion
.pipe(schema)Stage schemas

Zod Error Customization (v4)

v3v4
messageerror
invalid_type_errorerror function
required_errorerror function
errorMaperror function

Zod + React Hook Form

ElementCode
Installreact-hook-form zod @hookform/resolvers
Resolverresolver: zodResolver(Schema)
Form noValidate<form noValidate>
Field array keyfield.id
Cross-fieldregister("a", { deps: "b" })
TransformsuseForm<z.input<>, unknown, z.infer<>>

Security Rules

RuleDetail
YAMLsafe_load, alias limits
JSONSafe by default
TOMLSafe (no executable constructs)
DeserializationNo native formats on untrusted input
ProtobufField numbers permanent
Canonical serializationSign canonical bytes, not original

Streaming Formats

FormatSeparatorUse
JSON Lines\nLogs, data export
NDJSON\nSame, current name
JSON Text Sequence0x1E (RFC 7464)Newlines in records

Was this helpful?


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!