|
20 | 20 |
|
21 | 21 | - [Day 16](#day-16)
|
22 | 22 | - [JSON](#json)
|
23 |
| - - [Converting JSON to JavaScript Object](#converting-json-to-javascript-object) |
| 23 | + - [Convertire un JSON in Oggetto JavaScript ](#converting-json-to-javascript-object) |
24 | 24 | - [JSON.parse()](#jsonparse)
|
25 |
| - - [Using a reviver function with JSON.parse()](#using-a-reviver-function-with-jsonparse) |
26 |
| - - [Converting Object to JSON](#converting-object-to-json) |
27 |
| - - [Using a Filter Array with JSON.stringify](#using-a-filter-array-with-jsonstringify) |
| 25 | + - [Usare una funzione reviver con JSON.parse()](#using-a-reviver-function-with-jsonparse) |
| 26 | + - [Convertire un Oggetto in JSON](#converting-object-to-json) |
| 27 | + - [Usare un Filter Array con JSON.stringify](#using-a-filter-array-with-jsonstringify) |
28 | 28 | - [Esercizi](#exercises)
|
29 | 29 | - [Esercizi Livello 1](#exercises-level-1)
|
30 | 30 | - [Esercizi Livello 2](#exercises-level-2)
|
|
34 | 34 |
|
35 | 35 | ## JSON
|
36 | 36 |
|
37 |
| -JSON stands for JavaScript Object Notation. The JSON syntax is derived from JavaScript object notation syntax, but the JSON format is text or string only. JSON is a light weight data format for storing and transporting. JSON is mostly used when data is sent from a server to a client. JSON is an easier-to-use alternative to XML. |
| 37 | +JSON è l'acronimo di JavaScript Object Notation. La sintassi JSON deriva dalla sintassi della notazione degli oggetti JavaScript, ma il formato JSON è solo testo o stringa. JSON è un formato di dati leggero per la memorizzazione e il trasporto. JSON viene utilizzato soprattutto quando i dati vengono inviati da un server a un client. JSON è un'alternativa più facile da usare rispetto a XML. |
38 | 38 |
|
39 | 39 | **Esempio:**
|
40 | 40 |
|
@@ -63,9 +63,9 @@ JSON stands for JavaScript Object Notation. The JSON syntax is derived from Java
|
63 | 63 | }
|
64 | 64 | ```
|
65 | 65 |
|
66 |
| -The above JSON example is not much different from a normal object. Then, what is the difference ? The difference is the key of a JSON object should be with double quotes or it should be a string. JavaScript Object and JSON are very similar that we can change JSON to Object and Object to JSON. |
| 66 | +L'esempio JSON di cui sopra non è molto diverso da un normale oggetto. Allora, qual è la differenza? La differenza sta nel fatto che la chiave di un oggetto JSON deve essere con doppi apici o deve essere una stringa. Gli oggetti JavaScript e JSON sono molto simili, tanto che possiamo cambiare JSON in oggetto e oggetto in JSON. |
67 | 67 |
|
68 |
| -Let us see the above example in more detail, it starts with a curly bracket. Inside the curly bracket, there is "users" key which has a value array. Inside the array we have different objects and each objects has keys, each keys has to have double quotes. For instance, we use "firstNaMe" instead of just firstName, however in object we use keys without double quotes. This is the major difference between an object and a JSON. Let's see more examples about JSON. |
| 68 | +Vediamo in dettaglio l'esempio precedente, che inizia con una parentesi graffa. All'interno della parentesi graffa, c'è la chiave "utenti" che ha un array di valori. All'interno dell'array abbiamo diversi oggetti e ogni oggetto ha delle chiavi, ogni chiave deve avere i doppi apici. Per esempio, usiamo "firstNaMe" invece del semplice firstName, ma negli oggetti usiamo chiavi senza doppi apici. Questa è la differenza principale tra un oggetto e un JSON. Vediamo altri esempi di JSON. |
69 | 69 |
|
70 | 70 | **Esempio:**
|
71 | 71 |
|
@@ -167,9 +167,9 @@ Let us see the above example in more detail, it starts with a curly bracket. Ins
|
167 | 167 | }
|
168 | 168 | ```
|
169 | 169 |
|
170 |
| -### Converting JSON to JavaScript Object |
| 170 | +### Convertire un JSON in Oggetto JavaScript |
171 | 171 |
|
172 |
| -Mostly we fetch JSON data from HTTP response or from a file, but we can store the JSON as a string and we can change to Object for sake of demonstration. In JavaScript the keyword _JSON_ has _parse()_ and _stringify()_ methods. When we want to change the JSON to an object we parse the JSON using _JSON.parse()_. When we want to change the object to JSON we use _JSON.stringify()_. |
| 172 | +In genere si recuperano dati JSON dalla risposta HTTP o da un file, ma è possibile memorizzare il JSON come stringa e, a scopo dimostrativo, trasformarlo in oggetto. In JavaScript la parola chiave _JSON_ ha i metodi _parse()_ e _stringify()_. Quando vogliamo cambiare il JSON in un oggetto, lo analizziamo usando _JSON.parse()_. Quando vogliamo cambiare l'oggetto in JSON, usiamo _JSON.stringify()_. |
173 | 173 |
|
174 | 174 | #### JSON.parse()
|
175 | 175 |
|
@@ -211,9 +211,9 @@ const usersObj = JSON.parse(usersText, undefined, 4)
|
211 | 211 | console.log(usersObj)
|
212 | 212 | ```
|
213 | 213 |
|
214 |
| -### Using a reviver function with JSON.parse() |
| 214 | +### Usare una funzione reviver con JSON.parse() |
215 | 215 |
|
216 |
| -To use the reviver function as a formatter, we put the keys we want to format first name and last name value. Let us say, we are interested to format the firstName and lastName of the JSON data . |
| 216 | +Per utilizzare la funzione reviver come formattatore, si inseriscono le chiavi con cui si vuole formattare i valori di nome e cognome. Supponiamo di essere interessati a formattare il nome e il cognome dei dati JSON. |
217 | 217 |
|
218 | 218 | ```js
|
219 | 219 | const usersText = `{
|
@@ -247,19 +247,19 @@ const usersObj = JSON.parse(usersText, (key, value) => {
|
247 | 247 | console.log(usersObj)
|
248 | 248 | ```
|
249 | 249 |
|
250 |
| -The _JSON.parse()_ is very handy to use. You do not have to pass optional parameter, you can just use it with the required parameter and you will achieve quite a lot. |
| 250 | +Il metodo _JSON.parse()_ è molto comodo da usare. Non è necessario passare un parametro opzionale, basta usarlo con il parametro richiesto e si otterrà molto. |
251 | 251 |
|
252 |
| -### Converting Object to JSON |
| 252 | +### Convertire un Oggetto in JSON |
253 | 253 |
|
254 |
| -When we want to change the object to JSON we use _JSON.stringify()_. The stringify method takes one required parameter and two optional parameters. The replacer is used as filter and the space is an indentations. If we do not want to filter out any of the keys from the object we can just pass undefined. |
| 254 | +Quando vogliamo cambiare l'oggetto in JSON, usiamo _JSON.stringify()_. Il metodo stringify accetta un parametro obbligatorio e due parametri opzionali. Il sostituente è usato come filtro e lo spazio è una rientranza. Se non si vuole filtrare nessuna delle chiavi dell'oggetto, si può passare semplicemente undefined. |
255 | 255 |
|
256 | 256 | ```js
|
257 | 257 | JSON.stringify(obj, replacer, space)
|
258 | 258 | // json or text , the data
|
259 | 259 | // reviver is an optional callback function
|
260 | 260 | ```
|
261 | 261 |
|
262 |
| -Let us convert the following object to a string. First let use keep all the keys and also let us have 4 space indentation. |
| 262 | +Convertiamo il seguente oggetto in una stringa. Per prima cosa manteniamo tutte le chiavi e manteniamo un'indentazione di 4 spazi. |
263 | 263 |
|
264 | 264 | ```js
|
265 | 265 | const users = {
|
@@ -433,9 +433,9 @@ console.log(txt) // text means JSON- because json is a string form of an object.
|
433 | 433 | }
|
434 | 434 | ```
|
435 | 435 |
|
436 |
| -### Using a Filter Array with JSON.stringify |
| 436 | +### Usare un Filter Array con JSON.stringify |
437 | 437 |
|
438 |
| -Now, lets use the replacer as a filter. The user object has long list of keys but we are interested only in few of them. We put the keys we want to keep in array as show in the example and use it the place of the replacer. |
| 438 | +Ora, usiamo il replacer come filtro. L'oggetto utente ha un lungo elenco di chiavi, ma a noi interessano solo alcune di esse. Mettiamo le chiavi che vogliamo conservare in un array, come mostrato nell'esempio, e lo usiamo al posto del replacer. |
439 | 439 |
|
440 | 440 | ```js
|
441 | 441 | const user = {
|
@@ -464,7 +464,7 @@ console.log(txt)
|
464 | 464 | }
|
465 | 465 | ```
|
466 | 466 |
|
467 |
| -🌕 You are extraordinary. Now, you knew a light-weight data format which you may use to store data or to send it an HTTP server. You are 16 steps a head to your way to greatness. Now do some exercises for your brain and for your muscle. |
| 467 | +🌕 Sei straordinario. Ora conosci un formato di dati leggero che puoi usare per memorizzare i dati o per inviarli a un server HTTP. Sei a 16 passi dalla tua strada verso la grandezza. Ora fai qualche esercizio per il cervello e per i muscoli. |
468 | 468 |
|
469 | 469 | ## Esercizi
|
470 | 470 |
|
@@ -579,19 +579,19 @@ const txt = `{
|
579 | 579 |
|
580 | 580 | ### Esercizi Livello 1
|
581 | 581 |
|
582 |
| -1. Change skills array to JSON using JSON.stringify() |
583 |
| -1. Stringify the age variable |
584 |
| -1. Stringify the isMarried variable |
585 |
| -1. Stringify the student object |
| 582 | +1. Cambiare l'array di competenze in JSON usando JSON.stringify() |
| 583 | +1. Stringere la variabile età |
| 584 | +1. Stringere la variabile isMarried |
| 585 | +1. Stringere l'oggetto studente |
586 | 586 |
|
587 | 587 | ### Esercizi Livello 2
|
588 | 588 |
|
589 |
| -1. Stringify the students object with only firstName, lastName and skills properties |
| 589 | +1. Stringificare l'oggetto studenti con le sole proprietà firstName, lastName e skills |
590 | 590 |
|
591 | 591 | ### Esercizi Livello 3
|
592 | 592 |
|
593 |
| -1. Parse the *txt* JSON to object. |
594 |
| -2. Find the user who has many skills from the variable stored in *txt*. |
| 593 | +1. Analizzare il JSON *txt* in un oggetto. |
| 594 | +2. Trovare l'utente che ha molte competenze dalla variabile memorizzata in *txt*. |
595 | 595 |
|
596 | 596 | 🎉 CONGRATULAZIONI ! 🎉
|
597 | 597 |
|
|
0 commit comments