Skip to main content

How to use JSON

Here's a small example of how to use JSON in TypeScript:

interface Person {
name: string;
age: number;
}

const jsonString = '{"name": "John", "age": 30}';
const person: Person = JSON.parse(jsonString);

console.log(person.name); // Output: John
console.log(person.age); // Output: 30