Vai al contenuto principale
Tools Star Hub

Formattatore JSON

Formatta il JSON in modo leggibile, minificalo o verifica che sia valido. Commenti, virgole finali e apici singoli non sono ammessi. Non converte in CSV.

Caricamento dello strumento…

Questo strumento funziona nel tuo browser. Dati inseriti, file e valori generati restano su questo dispositivo. Preferiti e strumenti recenti, se li usi, salvano solo i nomi degli strumenti nella memoria locale: mai password, documenti o contenuti dei codici QR. Consulta l’informativa sulla privacy.

Per ora la guida dettagliata di questo strumento (come si usa, esempi e domande frequenti) è disponibile in inglese.

What this tool does

The JSON Formatter pretty-prints JSON, minifies it, or checks that it parses. Use it when an API response is one long line, or when a file fails and you need the parser’s position. The page uses the browser’s JSON parser. Comments, trailing commas, and single quotes fail. This page does not convert JSON to CSV.

How to use

  1. Paste JSON into the input box.
  2. Press Format to pretty-print with two-space indentation, Minify to remove extra spaces, or Validate to check the syntax without rewriting it.
  3. Copy the result, or Clear to empty both boxes.

Examples

  • A small object, formatted and minified

    Format turns {"name":"Ada","id":1} into a four-line object: an opening brace, then "name": "Ada", then "id": 1, then a closing brace, with two spaces of indentation. Minify of that pretty form returns {"name":"Ada","id":1}. Validate of the same input says: This JSON is valid. The keys and values do not change.

  • A trailing comma

    The input {"a":1,} does not format. The page reports Invalid JSON at position 7, then the browser’s parser message. Position 7 is the character after the comma, where a property name would have to start. Delete the comma before the closing brace.

  • A comment and single quotes

    {"a":1} // no fails at position 8, which is the slash after the object. {'a':1} fails at position 1, because a JSON key must use double quotes. The page does not strip comments or convert quotes. Fix the text, then Format again.

How it works

JSON is text for objects, arrays, strings, numbers, true, false, and null. Format and Minify both parse the text and then stringify it again. Format uses two-space indentation. Minify uses no extra space. Validate only parses, and on success it shows the sentence This JSON is valid. An empty box says: Paste JSON to format, minify or validate. A document longer than 750,000 characters is rejected before parsing.

What the parser accepts

Keys and strings use double quotes. Numbers are plain digits, with an optional fraction or exponent. Trailing commas are not allowed after the last item in an object or an array. Comments, including // and /* */, are not part of JSON.

Single quotes are a JavaScript habit, not JSON. {'a':1} fails. Undefined and functions are not JSON values. A trailing comma in a hand-written file is the most common reason Format fails on an otherwise familiar object.

Pretty print versus minify

Pretty print adds line breaks and indentation so a person can see the structure. Minify removes that whitespace so the text is shorter to paste. The data is the same if both operations succeed.

Stringify can change the spelling of a number that JavaScript cannot store exactly, and it drops undefined object values if they appear after a successful parse of a larger script you converted by hand. Standard JSON numbers and strings round-trip. The page does not sort keys.

How to use the error position

When the browser reports a position, the message starts with Invalid JSON at position, then the parser text. Count from the start of the pasted text, starting at 0 in the usual parser message, and look at that character. Position 7 in {"a":1,} is the spot after the comma.

If the message has no position, the page still says Invalid JSON and includes the parser text. The box is not rewritten when parsing fails. The previous output stays until a later success, so read the error before you trust the output box.

Privacy

Parsing and formatting happen in your browser. The JSON is not uploaded to Tools Star Hub and is not saved in local storage. Do not paste secrets you would not want in the page’s memory while the tab is open. Closing the tab or pressing Clear drops the text from the page.

Tips

  • Validate first when you only need a yes or no. Format when you need to read the structure. Minify when you need a single line.
  • Look one character left of the reported position. A trailing comma points at the next character, not at the comma itself.
  • Replace single quotes with double quotes yourself. The tool will not guess which quotes are keys.
  • For a CSV file, use the JSON to CSV tool after the JSON is valid. This page stops at formatting.

Limitations

Standard JSON is required: double quotes, no comments, and no trailing commas. A document longer than 750,000 characters is rejected. This formatter does not turn JSON into CSV and does not load a URL. The error text comes from the browser’s parser, so the wording after the position can vary slightly by browser. The position number is the one the parser reports.

See the disclaimer for what these tools do not cover.

FAQ

How do I format JSON?
Paste the JSON and press Format. {"name":"Ada","id":1} becomes a two-space indented object with name and id on their own lines. The values stay Ada and 1.
What is the difference between formatting and minifying JSON?
Format adds line breaks and two-space indentation. Minify removes that whitespace. Minify of the pretty Ada object returns {"name":"Ada","id":1}. The data is the same.
Why did formatting fail?
JSON must use double quotes, and it cannot include trailing commas or comments. {"a":1,} is reported as invalid JSON at position 7. A // comment after an object fails at the slash. {'a':1} fails at position 1.
What does Validate do?
Validate parses the text and, if it succeeds, shows: This JSON is valid. It does not pretty-print or minify. An empty box asks you to paste JSON.
Is there a size limit?
Yes. Text longer than 750,000 characters is rejected with a message that it is too large to process in the browser. Split the document and format a smaller piece.
Is my JSON uploaded?
No. Parsing and formatting happen in your browser.