MOX
Products
Learn about our additional services
Resources & Elements
Return

MOXSofía Paredes
07-10-2021

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

JSON (JavaScriptObjectNotation) is a format used to serialize or organize data. Its main characteristic is its simplicity, which results in lighter data files. Therefore, JSON is the standardized structure for organizing 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 entered between 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 have 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 so that each attribute has values, whether null, text strings, integers, or arrays. For example, if the object presents the following data:

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

In JSON format, we should enter:

 
{
"user1":
{
"firstname":"pedro",
"lastname":"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":{
"firstname":"pedro",
"lastname":"perez",
"user":"pedrope",
"age":18,
"country":"chile"
},
"user2":{
"firstname":"juan",
"lastname":"gonzalez",
"user":"juangonza",
"age":20,
"country":"argentina"
}
}


The values in our JSON structure can also be arrays, defined 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 example presented above and present it in XML format, we can better appreciate the character synthesis required by the JSON format:

 





18
perez
chile
pedro
pedrope


20
gonzalez
argentina
juan
juangonza






Of course, the more data you need to share, the more valuable this feature will be.

Despite JSON's efficiency when working with structured data, there are still private and state institutions that continue to use XML, such as the Internal Revenue Service, through their developer APIs.

Other articles that might interest you