cv.cm
All lessons

Developer tools

How to format JSON

You have text that should be JSON. You will paste it in this tab, pick pretty or minify, and copy a result that parsed. A log prefix in front of the brace is not JSON yet.

6-minute read

Today's result JSON that parsed: two-space indent, or one line, with the same keys and values you pasted.

Open the JSON formatter when the text is in front of you. Pretty uses two spaces. Minify is one line. Nothing is uploaded.

Open JSON formatter
Contents
  1. Decide reading layout or one line

    Pretty is for reading. Minify is for a header, a query, or a small file. Both parse first. Invalid text is not repaired for you.

    Pretty is two spaces for reading. Minify is one line for sending. Both must parse.
    Pretty is two spaces for reading. Minify is one line for sending. Both must parse.
  2. Open the JSON formatter on cv.cm

    Work stays in this tab.

    Open JSON formatter
  3. Paste the value, not the log prefix

    Start at the first { or [ and stop at its match. A time or the word INFO in front makes the whole paste invalid.

  4. If it says invalid, fix the text

    JSON wants double quotes, no comments, and no comma after the last item. Single quotes, undefined, and NaN are not JSON. An integer longer than 15 digits must be a string in quotes, or the digits can change.

    Copy the output. An integer longer than 15 digits belongs in quotes.
    Copy the output. An integer longer than 15 digits belongs in quotes.
  5. Copy the output

    Pretty is a two-space indent. Minify is one line. Copy that box, not the broken input.

  6. Check one value you already know

    A name, a count, or an id. If a long number changed, it was a bare integer past the safe range. Put it in quotes and format again.

FAQ

Can I format JSON free online?

Yes. cv.cm pretty-prints or minifies in this tab. Nothing is uploaded.

Why does my JSON fail?

Comments, a comma after the last item, and single quotes are not JSON. Strip a log prefix before the first brace.

What is the difference between pretty and minify?

Pretty indents with two spaces. Minify is one line. The values stay the same when the text parsed.

Are long numbers safe?

An integer longer than 15 digits can change unless it is a string in quotes.

Is the text uploaded?

No. Closing the tab discards it.