JSON

JavaScript Object Notation

8

.

XML. , 2000-, JSON.

JSON. , , , .


JSON?

JSON (JavaScript Object Notation, JavaScript) - . "-", - , :

  • ;
  • ;
  • ;
  • ;
  • ;
  • null.

:

  • JSON .
  • (:).
  • "-". (,).
  • JSON (// /* */). ( )

JSON:

{
    "name": "Alex C",
    "age": 2,
    "city": "Houston"
}

JSON 2 :

  • «-» {...}. .
  • «-», (,) [...]. . :
[
  {
        "name": "Alex C",
        "age": 2,
        "city": "Houston"
  },
    {
        "name": "John G",
        "age": 40,
        "city": "Washington"
  },
    {
        "name": "Bala T",
        "age": 22,
        "city": "Bangalore"
  }
]

, - JavaScript. , JSON JavaScript ( ) . . .

JSON JavaScript, , JSON JavaScript.

JSON . JSON Python, Java, PHP .


JSON

JSON .json. employee.json . .

{
  "name": "Aleix Melon",
  "id": "E00245",
  "role": ["Dev", "DBA"],
  "age": 23,
  "doj": "11-12-2019",
  "married": false,
  "address": {
    "street": "32, Laham St.",
    "city": "Innsbruck",
    "country": "Austria"
  },
  "referred-by": "E0012"
}  

:

  • name – . (String). .
  • id – . , .
  • role – , . , (Array).
  • age – . (Number).
  • doj – . , .
  • married – / ? / ( true false), (Boolean).
  • address – . : , , , .. (Object «-»).
  • referred-by – , . , . , .. null.

JSON. , [...].

[
  {
        "name": "Aleix Melon",
        "id": "E00245",
        "role": ["Dev", "DBA"],
        "age": 23,
        "doj": "11-12-2019",
        "married": false,
        "address": {
            "street": "32, Laham St.",
            "city": "Innsbruck",
            "country": "Austria"
            },
        "referred-by": "E0012"
  },
    {
        "name": "Bob Washington",
        "id": "E01245",
        "role": ["HR"],
        "age": 43,
        "doj": "10-06-2010",
        "married": true,
        "address": {
            "street": "45, Abraham Lane.",
            "city": "Washington",
            "country": "USA"
            },
        "referred-by": null
  }
]  

referred-by (Bob Washington). . .


JSON

, JSON. JSON . JSON , .

, JavaScript. JSON . '...'.

const user = '{"name": "Alex C", "age": 2, "city": "Houston"}';

, JSON (template literals).

const user = `{
    "name": "Alex C",
    "age": 2,
    "city": "Houston"
}`;

, , JSON .

const age = 2;

const user = `{
    "name": "Alex C",
    "age": ${age},
    "city": "Houston"
}`;

console.log(user);

// Output
{
    "name": "Alex C",
    "age": 2,
    "city": "Houston"
}  

JavaScript JSON –

JSON JavaScript. .

JavaScript:

  • JavaScript , JSON – ;
  • ;
  • ;

JSON JavaScript

JavaScript 2 JSON JavaScript .

JSON JavaScript

JSON JavaScript JSON.parse(). () JSON JavaScript.

const userJSONData = `{
    "name": "Alex C",
    "age": 2,
    "city": "Houston"
}`;

const userObj = JSON.parse(userJSONData);
console.log(userObj);  

:

JSON.parse()

JavaScript JSON

JavaScript JSON JSON.stringify().

const userObj = {
    name: 'Alex C', 
    age: 2, 
    city: 'Houston'
}

const userJSONData = JSON.stringify(userObj);
console.log(userJSONData);  

:

JSON.stringify()

, JSON, parse() stringify(). JavaScript, , JSON ( JSONUtil), JSON. , , .


"Unexpected token u in JSON at position 1" ?

JSON . . , JSON JavaScript :

  JSON

, JSON. , JSON. JSON JSON Linter.


40%
50%
60%
: 30 24 : 59 : 59