Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteTo make JSON compact, remove formatting whitespace while keeping the JSON structure: jq -c . input.json. To convert JSON to CSV, first decide how nested objects, arrays, missing keys, and null values should map to rows and columns. Compacting is a formatting change; CSV conversion is a data-shaping step, so it needs an explicit mapping.
Compact JSON and CSV solve different problems
Compact JSON remains JSON. It removes layout whitespace such as indentation and line breaks, but retains the parsed values and their structure. The JSON standard allows insignificant whitespace around structural characters, so removing that whitespace need not alter the JSON value. RFC 8259
As an Amazon Associate I earn from qualifying purchases.
CSV, by contrast, arranges fields into records. JSON supports primitive values—strings, numbers, booleans, and null—as well as objects and arrays. Objects can contain nested values; arrays are ordered and can contain mixed types. A CSV export therefore needs rules for choosing records, columns, and representations for values that do not fit naturally into a flat table. RFC 8259
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Minify JSON while retaining its parsed value
With jq installed, write compact output to a new file:
#1 Best Overall
- Author: Thomas Glover
- 864 pages
- 3.2" x 5.4", softbound
- (Also available in Desk Size item 2072)
jq -c . input.json > compact.json
The -c option, also called --compact-output, puts each JSON output value on one line. For an ordinary JSON input, this changes serialization and layout rather than converting the data into a table. Validate the output with a JSON parser. When checking whether content was retained, compare parsed values rather than text: whitespace and object member order may differ without changing the represented value.
Do not add jq’s -r option when the goal is JSON output. Raw mode writes string results without JSON string quoting, which can make the output unsuitable as a JSON document.
Parsing and reserializing is not byte-for-byte preservation. It may change whitespace, escape spellings, serialization choices, or member order. If exact source bytes matter, keep the original file. Duplicate object names are an additional hazard: RFC 8259 says names should be unique, and parser behavior for duplicates can vary—some implementations keep the last value, reject the object, or expose duplicates. If every textual occurrence matters, inspect for duplicates before ordinary parse-and-convert processing. RFC 8259
Choose a CSV mapping before converting
- Define what counts as a record. Identify the array or other collection of records, or decide how a single object or top-level scalar should become rows. A JSON document is not necessarily an array of flat objects.
- Choose the columns and headers. For records with different keys, decide whether columns come from a fixed schema, the union of keys, or a selected subset. Keep the decision consistent so each value lands under the intended header.
- Set a policy for nested values. Choose whether to put an object or array into one cell as JSON text, flatten object paths into columns, or expand array elements into rows. These produce different table shapes; flattening and expansion are not neutral formatting changes.
- Specify how to represent missing and empty values. Decide how absent keys,
null, empty strings, empty arrays, and empty objects appear. If the CSV representation could make two source states look the same, define sentinels or keep a schema or sidecar that records the distinction. - Use a CSV serializer and check the result. Do not create rows by simply joining values with commas. Verify headers, row alignment, and how the receiving application imports the file.
Pick a nested-value strategy
| Strategy | What it does | Trade-off |
|---|---|---|
| JSON text in a cell | Stores an object or array as serialized JSON in one CSV field. | Retains the nested value’s structure as text, but the cell is not native nested data and may be less convenient to analyze. |
| Flatten object paths | Turns nested object properties into columns, such as a path representing a child property. | Can make fields easier to inspect in a table, but changes the shape and requires consistent path and collision rules to reconstruct reliably. |
| Expand arrays into rows | Creates one or more rows from array elements. | Can help with row-based analysis, but may repeat parent values and lose element grouping unless identifiers and expansion rules are retained. |
For the least destructive export of nested values, keeping each object or array as JSON text in a cell is often the clearest choice. It does not make CSV a fully reversible substitute for JSON: the value is text in a field, and the CSV still needs a defined schema and escaping rules.
Rank #3
Escape CSV fields and test edge cases
Under the common CSV convention described by RFC 4180, fields containing commas, double quotes, or line breaks should be enclosed in double quotes; a double quote inside a quoted field is doubled. Use a serializer that applies the rules rather than building CSV by hand. RFC 4180
Before relying on a conversion, check representative input containing commas, quotes, CR/LF line breaks, Unicode, nulls, empty values, absent keys, nested objects, nested arrays, and mixed-type array elements. These are validation cases to run against the specific converter and receiving application; behavior can depend on the tool and its settings.
Rank #4
What “without losing data” can mean
For compact JSON, it can mean preserving the parsed JSON value while changing its serialization. It does not guarantee the original bytes, whitespace, escape spellings, or member order.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchFor CSV, it can mean retaining selected values under a documented mapping. CSV does not inherently preserve JSON’s nested types or distinguish an absent key from null or an empty string in every representation. Reconstructing the original reliably requires a reversible encoding convention and its schema. If exact preservation of arbitrary JSON structure is required, keep JSON as the canonical file and treat CSV as a defined export view.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




