Choosing a Format
Trade-offs.
Three Formats, Three Jobs
You now know JSON, CSV, and YAML. Each shines in different situations. Picking the right one keeps your data easy to produce, store, and consume.
- JSON for APIs and web
- CSV for tabular/spreadsheet data
- YAML for configuration
puts ['JSON', 'CSV', 'YAML'].join(', ')JSON Strengths
JSON is compact, universally supported, and maps to nested Hashes and Arrays. It is the de facto standard for web APIs and data interchange between services.
require 'json'
puts({ id: 1, items: [1, 2] }.to_json)All lessons in this course
- Reading and Writing JSON
- Working with CSV
- YAML Configuration
- Choosing a Format