minimal/json
JSON = JavaScript Object Notation, syntaxe pour stocker et échanger des données
De l’objet au JSON
$ node
> let obj = { fullname: "J.C. Buisson", hobbies: ["tennis", "electronics"], weight: 73, height: 1.87 }
undefined
> let json = JSON.stringify(obj) ; json
{"fullname":"J.C. Buisson","hobbies":["tennis","electronics"],"weight":73,"height":1.87}
Du JSON à l’objet
$ node
> let json = '{ "fullname": "J.C. Buisson", "hobbies": ["tennis", "electronics"], "weight": 73, "height": 1.87 }'
undefined
> let obj = JSON.parse(json) ; obj
{ fullname: 'J.C. Buisson',
hobbies: [ 'tennis', 'electronics' ],
weight: 73,
height: 1.87 }
> let json2 = "{ 'fullname': 'J.C. Buisson', 'hobbies': ['tennis', 'electronics'], 'weight': 73, 'height': 1.87 }"
undefined
> let obj2 = JSON.parse(json2)
undefined
> obj === obj2
true
ATTENTION : dans une chaîne JSON, les propriétés sont OBLIGATOIREMENT encadrées par des guillemets