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": valuepairs - Strings: Always use double quotes (
"hello"), never single quotes - Numbers: No quotes around numbers (
42, not"42") - Booleans: Lowercase
trueandfalse(notTrue) - Null: Lowercase
null(notNoneornil) - 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
nullor 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