What is JSON? What is it for and how does it work?

20

I often come across this JSON but I do not know what it's for and how it works.

    
asked by Jefferson Alison 04.02.2014 в 13:50
source

4 answers

32

Concept:

JSON, in its theoretical meaning is "Javascript Object Notation", of which nothing more is the lightest format known to me of transfer / data exchange, it is similar to XML , and has the same utility, even though it is lighter, the detail is that not necessarily, despite the name, you have to use it with Javascript. Many languages today support JSON, it's kind of a new method, substitute for the old and known XML . It is widely used to return data from a server using AJAX requests to update data in real time.

Information and Examples:

Many well-respected companies and systems nowadays use JSON, such as Google and Yahoo. With it we can store data in a way that works as follows:

We have a simple JSON object, it should contain a denotation (which is strongly recommended) or not, such as:

{"ObjetoPai":"valor"}

Now I'm going to show a more complex JSON object with parent objects and child object.

{
"ObjetoPai":{
    "ObjetoFilho":"valor"
  }
}

We can have an Array of child objects, too:

{

    "ObjetoPai":[
        {
            "ObjetoFilho":"valor"
        },
        {
            "ObjetoFilho":"valor"
        }
    ]

}

JSON can be complex, you can have more than one parent object with children as well, and for types it accepts integer, boolean values as well as strings, as you can see:

{

    "ObjetoPaiGeral":[
        {
            "ObjetoSubPai":{
                "ObjetoFilho":1
            }
        },
        {
            "ObjetoSubPai":{
                "ObjetoFilho":true
            }
        },
        {
            "ObjetoSubPai":{
                "ObjetoFilho":"string"
            }
        }
    ]

}

It can be easily stored inside a variable as an Object, thus making its usability easy, and can access values programmatically, for example in Javascript declaring and accessing the last example above:

var JSONObject = {

        "ObjetoPaiGeral":[
            {
                "ObjetoSubPai":{
                    "ObjetoFilho":1
                }
            },
            {
                "ObjetoSubPai":{
                    "ObjetoFilho":true
                }
            },
            {
                "ObjetoSubPai":{
                    "ObjetoFilho":"string"
                }
            }
        ]

    };

Accessing values:

JSONObject;                                            //objeto geral em si
JSONObject.ObjetoPaiGeral;                             //array dos sub pais
JSONObject.ObjetoPaiGeral[0];                          //acessando o primeiro filho do pai geral
JSONObject.ObjetoPaiGeral[0].ObjetoSubPai;             //acessando o objetosubpai do primeiro filho do pai geral
JSONObject.ObjetoPaiGeral[0].ObjetoSubPai.ObjetoFilho; //aqui você tem um valor, que é o valor do objeto filho do sub pai que é filho do pai geral.
//Você pode utilizar o tamanho do Array para fazer um laço de repetição se quiser:
JSONObject.ObjetoPaiGeral.length; //retornará 3.

Currently it is one of the best methods to retrieve information from the server, especially in an application that requires updating of data in real time.

You can learn more about it here at Official JSON Site .

    
answered by 04.02.2014 / 20:14
source
19

JSON is an acronym for "JavaScript Object Notation", it is a light format for computer data interchange. JSON is a subset of JavaScript object notation, but its use does not require JavaScript exclusively.

This is a javascript notation, which can be written to a text file, such as a XML file. It can be used for the exchange of information through webservices. Because it is lighter than XML, it is increasingly used.

Join means junction. It can be to join two tables from a database , merge texts and so on. It is a fairly generic term that may have different meaning in each technology.

link

    
answered by 04.02.2014 в 14:27
5

JSON is a method of hierarchical coding of data, as XML, although simpler.

JSON was born within the context of Javascript - and being valid Javascript can be directly interpreted with eval (), although this is dangerous for security reasons. It is also interpretable directly in Python. but is now considered a generic method and supported by every programming language.

    
answered by 04.02.2014 в 19:34
4

Json and Join are completely different things.

Join is used in database when you want to return data from multiple tables which are related to each other. It should be used when you want to get data that is not in a table only.

Now the Json "uses JavaScript syntax to describe data objects, but is still platform independent." In this case, it is used when you want to do data exchange between applications. The Json format is widely used in the Front End environment for information exchange with the Backend

    
answered by 04.02.2014 в 14:31