1. Inicio
  2. /
  3. Blog
  4. /
  5. Formato JSON, ¿qué es y para qué sirve?

JSON format, what is it and what is it for?

JSON format for data exchange between servers

Léelo en Español / 4-6 mins.
formato json que es y para que sirve
JSON (JavaScriptObjectNotation) is a format used to serialize or sort data. Its main feature is its simplicity , which results in lighter data files. For this reason, JSON is the standardized structure for ordering data objects that require interaction between servers or information storage ahead of other more sophisticated and heavy options, such as XML.

JSON structure

The JSON format consists of two pairs of braces {} and [] that contain the structure where each attribute and non-numeric value will be enclosed in quotes {“attribute”: “value”} , separated by commas to group more attributes and values {"attribute": "value", "attribute": "value", "attribute:" value "} . Depending on the complexity of the object to be encoded, the structure may (or may not) carry values.

How to apply the JSON format to an "object"?

To apply a JSON format to an object, it is necessary to organize the content in such a way that each attribute has values, be they null, text strings, integers or arrays. For example, if the object has the following data:

User 1
Name: Pedro
Last name: Pérez
User: Pedrope
Age: 18
Country Chile

In JSON format , we should enter:

{
   "user1":
{
"name": "pedro",
"surname": "perez",
"user": "pedrope",
"age": 18,
"country": "chile"
}
}


If you need to add more objects (another user in this case), just add another structure separated by commas:

{
         "user1": {
            "name": "pedro",
            "surname": "perez",
            "user": "pedrope",
            "age": 18,
            "country": "chile"
         },
         "user2": {
            "name": "juan",
            "surname": "gonzalez",
            "user": "juangonza",
            "age": 20,
            "country": "argentina"
         }
      }


The values of our JSON structure can also be arrays, defining us using brackets [] :

[1,2,3,4,5,6]


Conclusions

The JSON format is ideal for exchanging data quickly and effectively between servers due to its lightness. If we take the previously presented example and present it in XML format , we can better appreciate the character synthesis that the JSON format requires:

<? xml version = "1.0" encoding = "UTF-8"?>
<root>
   <users>
      <element>
         <user1>
            <age> 18 </age>
            <surname> perez </surname>
            <country> chile </country>
            <name> Peter </name>
            <user> pedrope </user>
         </user1>
         <user2>
            <age> 20 </age>
            <surname> gonzalez </surname>
            <country> argentina </country>
            <name> john </name>
            <user> juangonza </user>
         </user2>
      </element>
   </users>
</root>


Of course, the more data that is required to be shared, the more noticeable this feature will be.

Despite the efficiency of JSON when working with structured data, today there are private and state institutions that still continue to use XML as an Internal Revenue Service through their APIs for developers.








VPS CHILE Servidor virtual para tus aplicaciones con IP dedicada. Discos de alta velocidad. La mejor performance en Chile.
HOSTING CHILE Hosting solución para proyectos web. Discos ssd de alta velocidad. Servicio ideal para todo tipo de proyecto.
VPN CHILE Solución para todo usuario. Navegar de forma segura y anónima en internet.

Lee también

Iniciar sesión





Regístrate Recuperar contraseña
Crear una cuenta





Iniciar sesión Recuperar contraseña
¿Olvidó su contraseña?





Iniciar sesión Regístrate
Cargando...