Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Working with JSON | Section
/
JavaScript Essentials for Backend

bookWorking with JSON

Stryg for at vise menuen

JSON is a format used to store and transfer data.

It looks similar to JavaScript objects, but it is always written as a string.

const jsonString = '{"name": "John", "age": 25}';

To work with JSON in JavaScript, you need to convert it.

To convert JSON into a JavaScript object, use JSON.parse:

1234
const jsonString = '{"name": "John", "age": 25}'; const data = JSON.parse(jsonString); console.log(data.name);
copy

To convert a JavaScript object into JSON, use JSON.stringify:

1234
const user = { name: "John", age: 25 }; const json = JSON.stringify(user); console.log(json);
copy
question mark

What does JSON.parse() do?

Vælg det korrekte svar

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 18

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Sektion 1. Kapitel 18
some-alt