Data formats: JSON, YAML, XML, CSV, and binary formats
Syntax, extensions, media types, use cases, and limitations of text, tabular, and binary formats.
Syntax, media type, and purpose
Click an example, extension, or media type to copy it. Binary examples are shown as hexadecimal bytes.
| Format | Example | Extension and MIME | When to use |
|---|---|---|---|
| Structured textHuman-readable formats for APIs, documents, and configuration. | |||
| JSON APIsstrict syntax | | The practical default for web APIs and application interchange: objects, arrays, and a small type set.Watch for: Comments, trailing commas, NaN, and Infinity are not part of JSON. | |
| YAML configurationcomments | | An expressive format for configuration and documents designed for human reading and editing.Watch for: Indentation is significant; type resolution and supported features depend on the parser version. | |
| TOML configurationexplicit types | | A predictable configuration format with explicit strings, numbers, dates, arrays, and tables.Watch for: Well suited to settings, but less convenient for deeply nested documents and data streams. | |
| XML documentsschemas | | Extensible markup for documents and integrations that need attributes, namespaces, and mature schemas.Watch for: Parsing is more complex and verbose; external entities should be disabled for untrusted input. | |
| Tables and streamsFlat records, exports, and line-by-line data processing. | |||
| CSV tablesspreadsheets | | A common tabular interchange format with one record per row and comma-separated fields.Watch for: Agree on delimiter, encoding, header presence, and quote escaping before interchange. | |
| TSV tablestab-delimited | | A table whose fields are separated by tabs; useful when values frequently contain commas.Watch for: Tabs and line breaks inside values still require agreed escaping rules. | |
| JSON Lines / NDJSON logsstreams | Media type is not standardized yet | Each line is an independent JSON value, so records can be read, appended, and streamed one at a time.Watch for: A blank line is not a record; use UTF-8 and separate every value with a line terminator. | |
| Compact binary formatsLess bandwidth and faster parsing, but a specialized decoder is required. | |||
| CBOR binaryschema-free | | A standardized compact binary representation with types, tags, and self-describing decoding without an external schema.Watch for: Bytes are not human-readable; signatures and hashes require a separately agreed deterministic encoding mode. | |
| Protocol Buffers binaryschema | | Schema-based serialization with numeric field identifiers, compact messages, and generated code for many languages.Watch for: Decoding requires a compatible schema; field numbers must not be reused after removal. | |
| MessagePack binaryschema-free | Common, but not an IANA-registered media type | Compact binary serialization with a JSON-like data model and extensible application-defined types.Watch for: There is no single registered media type; extensions and custom types must be agreed by both sides. | |
Start from the task, not the syntax
- Public web APIJSON
- Broad support, predictable syntax, and a registered media type.
- Configuration for peopleTOML or YAML
- TOML favors explicit settings; YAML handles richer document shapes.
- Complex documentsXML
- Choose it when namespaces, mixed content, signatures, or mature schema tooling matter.
- Spreadsheet exportCSV or TSV
- Agree on delimiter, encoding, header, line endings, and escaping before exchange.
- Logs and streamsJSON Lines
- One independent JSON value per line can be appended and processed incrementally.
- Compact transportCBOR, Protobuf, or MessagePack
- Use Protobuf for schema-first contracts; CBOR or MessagePack for self-describing values.
JSON, YAML 1.2.2, TOML 1.0.0, XML 1.0, CSV, JSON Lines, CBOR, Protocol Buffers and MessagePack.
Continue working with text
Copy a symbol, convert markup, clean a fragment, or keep the result in the notebook.
- Encode HTML entities Turn special characters into safe HTML entities or decode them back.
- Convert Markdown to HTML Prepare HTML markup from a Markdown draft.
- Remove HTML tags Keep readable text and discard markup.
- Change text case Convert letters to upper or lower case.
- Open the online notebook Use copied symbols in a note stored locally in your browser.
Questions about data formats
Which data format should a new API use?
JSON is the safest default for a public HTTP API because tooling and media-type support are nearly universal. Choose a binary format only when both sides control the contract and size or speed justifies the extra tooling.
Is YAML a superset of JSON?
YAML 1.2 was designed so that JSON documents can be accepted as YAML, but parser versions and implementation details still matter. Do not assume every YAML 1.1 parser behaves like YAML 1.2.
Why does the same CSV file open differently in different programs?
CSV ecosystems vary in delimiter, decimal separator, encoding, line endings, and header detection. RFC 4180 documents a common form, not every dialect used in practice.
How does JSON Lines differ from a JSON array?
JSON Lines stores each value as a separate line, which supports appending and streaming. The complete file is not one JSON array and must be parsed record by record.
Do binary formats automatically make data secure?
No. Binary serialization can reduce size and parsing cost, but it does not provide encryption, authentication, validation, or safe resource limits by itself.