Object Construction & Reshaping with jq
Intermediatev1.0.0
Reshape JSON data with jq — constructing new objects, renaming fields, merging structures, string interpolation, and building output formats like CSV, TSV, and custom templates.
Content
Overview
jq's object construction syntax lets you reshape JSON data into any structure. Rename fields, merge objects, interpolate strings, and convert JSON to CSV, TSV, or custom text formats.
Why This Matters
- -Data transformation — reshape API responses for downstream systems
- -Format conversion — convert JSON to CSV, TSV, or custom formats
- -Field normalization — standardize field names across data sources
- -Reporting — build human-readable summaries from JSON data
How It Works
Step 1: New Object Construction
Step 2: Object Merging
Step 3: String Interpolation
Step 4: Format Conversion
Best Practices
- -Use string interpolation \() for readable templates
- -Use @csv/@tsv for proper escaping in delimited output
- -Use * for deep merge, + for shallow merge
- -Use to_entries/from_entries for key-value transformations
- -Always use -r flag with string output formats
Common Mistakes
- -Forgetting -r flag (output includes JSON quotes)
- -Using + instead of * for nested object merge (shallow only)
- -Building CSV manually instead of using @csv (escaping issues)
- -Not handling null values in string interpolation
- -Using string concatenation instead of interpolation syntax
FAQ
Discussion
Loading comments...