Jak formatovat JSON jako profesional

Kompletni pruvodce formatovanim JSON: pravidla syntaxe, caste chyby, osvedcene postupy a priklady z praxe.

Co je JSON a proc zalezi na formatovani

JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write, and easy for machines to parse and generate. Proper formatting -- also called "pretty-printing" -- adds indentation, line breaks, and consistent spacing that makes JSON far more readable than a minified single-line string.

Pravidla syntaxe JSON

  • Key-value pairs: Data is stored as "key": value pairs
  • Strings: Always use double quotes ("hello"), never single quotes
  • Numbers: No quotes around numbers (42, not "42")
  • Booleans: Lowercase true and false (not True)
  • Null: Lowercase null (not None or nil)
  • Arrays: Square brackets [1, 2, 3]
  • Objects: Curly braces {"key": "value"}
  • Commas: Separate items with commas, but no trailing comma after the last item

Caste chyby v JSON a jak je opravit

  • Single quotes: JSON requires double quotes. {'key': 'value'} is invalid. Fix: {"key": "value"}
  • Trailing commas: {"a": 1,} is invalid. Remove the last comma.
  • Comments: JSON does not support // or /* */ comments. Remove them.
  • Unquoted keys: {key: "value"} is invalid. JSON requires {"key": "value"}
  • NaN/Infinity: Not valid JSON. Use null or a string representation.

Priklady z praxe

Here is a well-formatted JSON object representing a user profile:

{
  "name": "Jane Doe",
  "email": "jane@example.com",
  "age": 30,
  "active": true,
  "roles": ["admin", "editor"],
  "address": {
    "city": "Prague",
    "country": "Czech Republic"
  },
  "preferences": null
}

Use our JSON Formatter tool to instantly beautify any minified JSON.

Osvedcene postupy pro praci s JSON

  • Always validate JSON before using it in production
  • Use 2-space indentation for readability
  • Keep JSON files under 1MB for browser performance
  • Use consistent key naming (camelCase or snake_case)
  • Consider JSON Schema for complex data validation

Casto kladene dotazy

What is the difference between JSON and JavaScript objects?
JSON is a text-based data format with strict rules (double quotes only, no functions, no comments). JavaScript objects are more flexible and can contain functions, undefined values, and single-quoted strings.
Can JSON contain comments?
No. Standard JSON (RFC 8259) does not support comments. Some parsers accept them as an extension (JSONC), but it is not standard and will break many tools.
What is the maximum size of a JSON file?
There is no official limit, but browsers typically handle JSON files up to 30-50MB before performance degrades. For larger datasets, consider streaming parsers.
How do I minify JSON?
Remove all whitespace, line breaks, and indentation. This reduces file size for network transfer. Our JSON Formatter tool can both beautify and minify JSON.
Is JSON case-sensitive?
Yes. "Name" and "name" are completely different keys in JSON. Always use consistent casing.