Utvikling · verktøy

JSON-formaterer

Lim inn JSON, og formater den eller gjør den mindre. Feil forklares tydelig.

Kjøres i nettleseren. Ingen opplasting.

Paste JSON to validate it.

Om verktøyet

JSON-formaterer sem complicação.

JSON-dataene dine blir i denne nettleserfanen. Ingenting sendes til en server.

Veiledning

Slik bruker du JSON-formaterer

The JSON Formatter checks whether pasted text is valid JSON, then either spreads it over indented lines or packs it onto a single line. Formatting uses two spaces. Your text is kept as you wrote it: number spellings, key order and repeated keys all stay. It does not repair broken JSON, accept comments or single quotes, sort keys, or turn JSON into another format.

Slik gjør du

  1. Paste or type your JSON into the JSON to format box.
  2. Press Format JSON for readable, two-space indentation, or Minify to remove the extra spaces and line breaks.
  3. Read the message under the box. A valid document shows a success message; an invalid one shows the error and where the parser stopped.
  4. Press Copy result to copy the output, or Clear to empty both boxes.

Eksempler

Formatting a small object

Du skriver inn
Handling
Format JSON
Tekst
{"b":1.0,"a":[1,2,{"c":null}]}
Du får
Resultat
{ "b": 1.0, "a": [ 1, 2, { "c": null } ] }
Melding
Gyldig JSON. Resultatet er klart.

Every item moves to its own line and each level is indented by two spaces. The key order stays b then a, and 1.0 stays 1.0.

Kjørt med verktøyets egen kode.

A repeated key is kept

Du skriver inn
Handling
Format JSON
Tekst
{"b":1.0,"a":[1,2,{"c":null}],"b":2}
Du får
Resultat
the same object with both "b" entries, ending in "b": 2
Melding
Valid JSON. Duplicate keys are preserved; some readers keep only the last value.

The text is valid, so it is formatted, and the first b is not dropped. The message warns you because other programs may keep only the last value for a repeated key.

Kjørt med verktøyets egen kode.

Large numbers are not rounded

Du skriver inn
Handling
Format JSON
Tekst
{"price":12345678901234567890,"e":1E+2,"empty":{},"list":[]}
Du får
Resultat
{ "price": 12345678901234567890, "e": 1E+2, "empty": {}, "list": [] }

A plain JavaScript parse-and-print would turn the first number into 12345678901234567000 and the second into 100. This tool copies the numbers as typed, so what you paste is what you get back.

Kjørt med verktøyets egen kode.

A trailing comma

Du skriver inn
Handling
Format JSON
Tekst
{"a":1,}
Du får
Melding
This JSON has an error: Expected double-quoted property name in JSON at position 7 (line 1 column 8)

JSON does not allow a comma before the closing brace. The wording of the error comes from your browser's own parser, so it can differ from one browser to another. No output is shown.

Kjørt med verktøyets egen kode.

Når det er nyttig

  • Read a long one-line API response by spreading it over indented lines.
  • Shrink a config or sample payload onto one line before pasting it into a request or a test.
  • Find a missing quote, comma or bracket in hand-edited JSON.
  • Clean up JSON from a log file without letting large IDs or prices change.

Begrensninger

  • Only strict JSON passes. Comments, single quotes, trailing commas, unquoted keys and values like NaN or undefined are errors.
  • Formatting always uses two spaces. There is no choice of four spaces or tabs on the page.
  • The tool does not sort keys, remove repeated keys, fix mistakes or compare two documents.
  • A document that takes more than 5 seconds to process is stopped and you see a message asking for a smaller one.

Tips

  • If you see an error, look at the position in the message first; the problem is usually just before it.
  • Keep the original text when you minify, because minified JSON is hard to read and edit.
  • Do not paste secrets such as passwords or tokens into any online page, even one that runs locally, if you can use dummy values instead.

Kilder

Vanlige spørsmål

Sobre JSON-formaterer.

What counts as valid JSON here?

The text must follow the JSON grammar of RFC 8259: double-quoted keys and strings, no trailing commas, no comments, and only the literals true, false and null. Your browser's built-in parser does the check, so the rules match what that browser accepts.

Does the tool change my numbers?

No. It copies each number exactly as you wrote it, including long integers and forms like 1E+2. Many tools that parse and re-print JSON round big numbers, so this matters for IDs and prices. The formatter only changes the spaces and line breaks.

Why does it keep repeated keys?

JSON text may contain the same key twice, and the standard says keys should be unique. Because this tool does not rebuild the data, it keeps both and shows a warning. A program that reads the file may use only the last value.

What is the difference between Format and Minify?

Format adds line breaks and two-space indents so a person can read it. Minify removes every space and line break that sits outside the strings, so the document is as short as possible. Both keep the data the same.

Why do I see a different error message in another browser?

The tool shows the message from your browser's own JSON parser, and each browser words it differently. The position, such as line and column, is the useful part. Read it, then check the quotes, commas and brackets near that spot.

Is my JSON uploaded?

No. The checking and formatting run in your browser, in a background worker on the page. The tool has no server step for your text. Close the tab and the text is gone, as nothing is saved by this tool.

Can it fix invalid JSON for me?

No. It tells you that the text is invalid and where the parser stopped, but you have to make the change yourself. This keeps your data from being altered in a way you did not intend.

Hvordan bruker du JSON-formaterer?

Lim inn JSON, og formater den eller gjør den mindre. Feil forklares tydelig.

Lastes dataene mine opp til en server?

Nei. Behandlingen skjer i nettleseren din, og opplysningene dine lastes ikke opp.