Phanith NY
← JSON Editor & Diff guides

How to format and minify JSON on Mac

By Phanith NY ·

On Mac, use Format for a readable copy of valid JSON and Minify for a compact copy. Both actions are available in JSON Editor & Diff. Start with a saved original and validate the result. Compare the values you get when the text is parsed, especially spaces inside strings and the order of array items.

How to format and minify JSON on Mac — JSON Editor & Diff guide

Choose a readable copy or a compact copy

Format when a person needs to review the structure. Indentation and line breaks make it easier to tell which values belong to an object or array. Minify when you want a compact payload to paste into a test field. Decide which copy you need before changing the file; keep the original available for comparison.

JSON allows insignificant whitespace around punctuation such as braces, brackets, colons and commas. Spaces within a quoted value can be part of the data. Removing whitespace with a blanket find-and-replace can change a label even when the document still parses.

Work through a label with two spaces

Use this example: { "label": "Desk\u0020\u0020A", "ports": [80, 443] }. Each \u0020 represents one space when parsed, so there are two spaces between Desk and A. The escapes make the spaces visible in this guide.

A compact representation is {"label":"Desk\u0020\u0020A","ports":[80,443]}. The spaces around the JSON punctuation went away. The decoded label still contains two spaces, and the array still contains 80 followed by 443. A formatter may write those spaces literally rather than as escapes; check the decoded value before concluding it changed.

Use Format and Minify in JSON Editor & Diff

JSON Editor & Diff validates text as you edit and offers separate Format and Minify actions for the active editor. Use a copy of the valid input, focus its editor and choose the action you need. If you keep both copies, give them distinct names so a compact payload does not replace the version meant for review.

The app documents normalized output. Key order and the spelling of escapes can differ even when the parsed values in this example match. If a later step expects the exact bytes of the original file, keep using that file.

  1. Preserve the original and confirm the working copy is valid JSON.
  2. Choose Format for review or Minify for compact text.
  3. Check that the label contains two spaces and the ports are still in order.
  4. Save the result as a separate copy if you need to keep it.

Check the values that matter after editing

Validation checks syntax. A valid result could still hold the wrong label if a manual edit removed one of its spaces. Compare the decoded string, the numeric values and their array positions. If a value changed, go back to the original and investigate before passing the new file along.

If validation fails, fix the reported syntax issue before choosing a layout. For a final handoff, use the readable copy for review and the compact copy for the test field. Keep both traceable to the same original.

Questions

Should I delete all whitespace to minify JSON?

Use a JSON-aware Minify action. Whitespace around structural punctuation can be insignificant, while a space inside a quoted value is part of the string.

Why does my formatted output look different even when the values match?

A serializer can change indentation, object key order or the written form of an escape. Compare parsed values and preserve the original if exact text matters.

Should the array order change when I format a file?

Formatting the example should keep 80 before 443. Array order is part of the data, so check it along with the values.

Sources

Download JSON Editor & Diff