Le Guide Complet JSON
Tout ce que vous devez savoir sur JSON — format, validation, outils et bonnes pratiques.
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format built on two universal structures: objects (name/value pairs) and arrays (ordered lists). It has become the dominant format for REST APIs, configuration files, and data storage in modern web development.
JSON Syntax Rules
- Keys must be strings in double quotes
- No trailing commas after the last item
- No JavaScript comments (
// or /* */) - Strings use double quotes only — no single quotes
- Supported types: string, number, boolean, null, object, array
Working with JSON in JavaScript
// Parse JSON string → JavaScript object
const obj = JSON.parse('{"name":"Alice","age":30}');
// Convert object → JSON string (indent = 2 spaces)
const json = JSON.stringify(obj, null, 2);
// Safe parsing
try {
const data = JSON.parse(userInput);
} catch (e) {
console.error('Invalid JSON:', e.message);
} Common JSON Errors
- Unexpected token — missing/extra comma, or unquoted key
- Unexpected end of input — unclosed bracket, brace, or string
- Invalid character — single quotes or a comment in the JSON
JSON vs XML
JSON is typically 30–40% more compact than equivalent XML, maps directly to JavaScript objects, and is faster to parse. XML remains preferable for documents requiring namespaces, schemas (XSD), or comments.
Frequently Asked Questions
Can JSON have comments?
No. Use JSONC or YAML for configuration files that need comments.
How do I handle dates in JSON?
Use ISO 8601 strings: "2024-01-15T10:30:00Z". JSON has no native date type.
What is NDJSON?
Newline Delimited JSON — one JSON object per line. Ideal for streaming large datasets and log files.
What file size can VisualDevTools handle?
All processing is in your browser. Works well up to 50MB on modern computers — no server upload needed.
Related Tools
Formateur JSON
Embellissez et formatez du JSON avec coloration syntaxique.
Validateur JSON
Validez la syntaxe JSON instantanément avec des messages d'erreur détaillés.
Minificateur JSON
Minifiez le JSON en supprimant les espaces et le formatage.
JSON vers CSV
Convertissez des tableaux JSON en format CSV pour tableurs.
JSON vers XML
Convertissez des données JSON en format XML valide instantanément.
Comparaison JSON
Comparez deux objets JSON et mettez en évidence leurs différences.