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

JSON format for data exchange between servers

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:

"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 [] :



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"?>
            <age> 18 </age>
            <surname> perez </surname>
            <country> chile </country>
            <name> Peter </name>
            <user> pedrope </user>
            <age> 20 </age>
            <surname> gonzalez </surname>
            <country> argentina </country>
            <name> john </name>
            <user> juangonza </user>

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.