JSON: Por que a web moderna depende dele?
Se você atua no mundo da TI, provavelmente já se deparou com a sigla JSON milhares de vezes. Mas o que é isso exatamente e por que esse formato substituiu o outrora popular XML? Hoje, vamos olhar 'sob o capô' desse formato de dados leve. změna
Mañana en el cañón. Coração e Ações.
What is JSON?
JSON (JavaScript Object Notation) é um formato de troca de dados baseado em texto. Foi concebido para ser fácil de ler e escrever por humanos e, ao mesmo tempo, fácil de analisar e gerar por máquinas. Apesar de ter "JavaScript" no nome, é independente de linguagem — hoje em dia, é suportado por tudo, desde Python e PHP até C#.
Se você atua no mundo da TI, provavelmente já se deparou com a sigla JSON milhares de vezes. Mas o que é isso exatamente e por que esse formato substituiu o outrora popular XML? Hoje, vamos olhar 'sob o capô' desse formato de dados leve.
Se você atua no mundo da TI, provavelmente já se deparou com a sigla JSON milhares de vezes. Mas o que é isso exatamente e por que esse formato substituiu o outrora popular XML? Hoje, vamos olhar 'sob o capô' desse formato de dados leve.
Se você atua no mundo da TI, provavelmente já se deparou com a sigla JSON milhares de vezes. Mas o que é isso exatamente e por que esse formato substituiu o outrora popular XML? Hoje, vamos olhar 'sob o capô' desse formato de dados leve.
- test test
Why Does Everyone Love It?
- Minimalism: It doesn't contain any unnecessary tags.
- Speed: Thanks to its small footprint, data transfers at lightning speeds.
- Structure: It maps perfectly to common data structures like lists and objects.
What Does the Syntax Look Like?
JSON works with two fundamental structures:
- Object: A collection of key: value pairs enclosed in curly braces {}.
- Array: An ordered list of values enclosed in square brackets [].
Practical Example:
Imagine we are sending data about a user:
JSON
{
"id": 101,
"name": "John Doe",
"active": true,
"roles": ["admin", "editor"],
"address": {
"city": "Prague",
"zip": 11000
}
Data Types in JSON
In JSON, you can use the following value types:
- String – must always be in "double quotes."
- Number – both integers and floating-point numbers.
- Boolean – true or false.
- Array – a list of values.
- Object – nested data.
- Null – an empty value.
JSON vs. XML: Who Won?
XML used to be the primary choice for data transfer. Why do most developers choose JSON today?
| Feature | JSON | XML |
| Readability | Very higher | Lower (too many tags) |
| Size | Small (efficient) | Large |
| Parsing | fast (native in JS) | Slower |
| Typing | Supports numbers, boolean | Everything is text |
What to Watch Out For (Common Mistakes)
Even though JSON is simple, beginners often trip over details that can "break" an entire application:
- Missing quotes on keys: Keys must be in double quotes (e.g., "name": "John").
- Trailing commas: JSON cannot handle a comma after the last item in an object or array.
- Double vs. Single quotes: Only double quotes " are permitted in JSON.
JSON is indispensable today. Whether you are building a simple website or a complex mobile app, you can't live without it. It is the universal language of data, saving time for developers and resources for servers.
Want to know more: Connect via LinkedIn or check link