Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use jq -c . input.json to remove JSON formatting whitespace while keeping the parsed JSON structure. Converting JSON to CSV is different: CSV has rows and fields but no native representation for nested objects, arrays, or the distinction between a missing value and null. To preserve useful information, define how those values map to columns and rows before exporting.

Compact JSON and CSV solve different problems

Compact JSON, often called minified JSON, removes layout whitespace such as indentation and line breaks. The result is still JSON, with its objects, arrays, values, and nesting intact. RFC 8259 permits insignificant whitespace around JSON’s structural characters, so removing that whitespace does not change the parsed value (RFC 8259).

CSV is a tabular format: values are arranged in records and fields. JSON can contain nested objects and ordered arrays as well as strings, numbers, booleans, and null. There is no universal way to turn every JSON document into one table without choosing a mapping. RFC 8259 describes arrays as ordered sequences and objects as collections of name/value pairs; that structure does not automatically correspond to CSV rows and columns.

Goal Output remains JSON? Nested data Can the original be reconstructed?
Compact JSON Yes Represented in the same structure Usually, from the parsed value; not necessarily byte-for-byte
JSON to CSV No Must be encoded in cells, flattened, or reshaped Only if the mapping and value distinctions are preserved

How to make compact JSON with jq

Install jq for your operating system, then run this command in a terminal from the directory containing the input file:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
jq -c . input.json > compact.json

The -c option, also called --compact-output, writes each JSON output value on one line, instead of pretty-printing it. The jq manual documents this behavior (jq manual). The command writes the result to compact.json and leaves input.json unchanged.

Check that the output parses as JSON, and compare parsed values rather than raw text. Parsing and reserializing can change details such as whitespace, escape spellings, and object-member order even when the value is equivalent. If you need to preserve the original bytes or the exact textual representation, keep the source file.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Do not add jq’s -r option when your goal is JSON output. Raw mode writes string results as unquoted text, which is useful in some text pipelines but may not produce a valid JSON document.

Choose a CSV row and column mapping first

Before converting, decide what one CSV row represents and which values become columns. A top-level array of flat objects is a common starting point, but JSON documents can instead have a single object, a scalar, nested structures, or records with different keys.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
  1. Identify the records. Decide whether an array element represents a row. For a single object or top-level scalar, specify whether it becomes one row, one field, or something else.
  2. Define the columns. For records with inconsistent keys, choose a fixed set of columns, the union of keys found across records, or a selected subset. Decide how headers are named.
  3. Set a policy for nested values. Choose whether each nested object or array stays together as JSON text in one cell, object paths become separate columns, or array elements are expanded into rows.
  4. Decide how to represent missing and empty values. Specify how an absent key, null, an empty string, an empty array, and an empty object will appear.
  5. Use a CSV serializer and check the result. Do not build rows by joining values with commas. Inspect the output in the application that will receive it.

Three ways to represent nested JSON in CSV

Mapping How it works Best suited to Main trade-off
JSON text in a cell Serialize a nested object or array as JSON and put the text in one field. Keeping the nested value together while exporting surrounding fields as columns The cell contains text, not a native nested object or array; consumers must parse it to work with its structure.
Flatten object paths Turn nested object properties into columns such as address.city. Searching, sorting, or analyzing selected nested properties as columns The original hierarchy needs a defined naming convention to reconstruct; flattening alone does not settle how arrays should be handled.
Expand arrays into rows Create multiple rows from array elements, often repeating values from the parent object. Analyzing each array item as a separate record This reshapes the data. Preserve parent identifiers and define what happens for empty or mixed-type arrays to avoid losing relationships.

These approaches are not interchangeable or inherently reversible. Keeping nested JSON text is often the least destructive choice for the nested value itself, but it still makes that value a text field in CSV. Flattening and row expansion can make data easier to analyze while changing its shape.

Preserve missing, null, and empty values deliberately

In JSON, a missing object key is not the same thing as a key whose value is null, an empty string, an empty array, or an empty object. A CSV cell that appears blank may not reveal which case it represents. If reconstructing the input matters, document a distinct encoding—such as a reserved sentinel with an escape rule—or keep a schema or sidecar that records the distinction. Make sure the encoding cannot be confused with legitimate input data.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

CSV does not intrinsically retain JSON’s nested types or all of these value distinctions. A round trip is only reliable when the CSV mapping and its decoding rules preserve every distinction you need; otherwise, retain the JSON as the canonical copy.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Quote CSV fields correctly

RFC 4180 describes a common CSV convention: fields containing commas, double quotes, or line breaks should be enclosed in double quotes, and a double quote inside a quoted field is doubled. For example, the text She said "hello" must be escaped by the serializer rather than inserted as raw text. Record line endings are conventionally CRLF in that RFC, though receiving applications and CSV implementations can differ (RFC 4180).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Using a CSV serializer matters for ordinary strings as well as nested JSON stored in a cell. Hand-joining fields with commas can break rows when a value itself contains a comma, quote, or line break.

Check the export against representative values

Before relying on a CSV export, test it with examples that exercise the mapping and the receiving application’s import behavior:

  • Strings containing commas, quote marks, CR/LF line breaks, or Unicode characters
  • null, empty strings, empty arrays, and empty objects
  • Records with absent keys and records with additional keys
  • Nested objects, nested arrays, and mixed-type array elements
  • Rows with expanded arrays, checking that parent identifiers and relationships remain clear

Confirm that each row aligns with the intended headers and that the target application displays values as expected. Spreadsheet import behavior depends on the application and its settings, so an export that is valid CSV may still need import options chosen explicitly.

Watch for duplicate JSON object names

RFC 8259 says object names SHOULD be unique. If a JSON object repeats a name, parser behavior can be unpredictable: software may keep the last value, reject the object, or expose multiple occurrences. If every textual occurrence matters, detect duplicate names before ordinary parse-and-convert processing; once a parser has discarded duplicates, a later CSV export cannot restore them.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What “without losing data” can mean

For compact JSON, it generally means preserving the parsed JSON value while changing formatting, not preserving the original bytes, whitespace, escape choices, or necessarily the order in which object members appeared. For CSV, it means preserving the values you selected under a documented mapping. Since CSV does not natively express JSON’s full structure and value distinctions, it cannot guarantee a lossless round trip without a reversible encoding and its schema. If exact preservation of arbitrary JSON matters, keep JSON as the source of truth and treat CSV as an export view.

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.