◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
2 changes: 1 addition & 1 deletion 1-js/05-data-types/12-json/1-serialize-object/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

```js
let user = {
name: "John Smith",
age: 35
};

Expand Down
6 changes: 3 additions & 3 deletions 1-js/05-data-types/12-json/1-serialize-object/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ importance: 5

---

# Turn the object into JSON and back

Turn the `user` into JSON and then read it back into another variable.

```js
let user = {
name: "John Smith",
age: 35
};
```
22 changes: 11 additions & 11 deletions 1-js/05-data-types/12-json/2-serialize-event-circular/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@ importance: 5

---

# Exclude backreferences

In simple cases of circular references, we can exclude an offending property from serialization by its name.

But sometimes we can't just use the name, as it may be used both in circular references and normal properties. So we can check the property by its value.

Write `replacer` function to stringify everything, but remove properties that reference `meetup`:

```js run
let room = {
number: 23
};

let meetup = {
title: "Conference",
occupiedBy: [{name: "John"}, {name: "Alice"}],
place: room
};

*!*
// circular references
room.occupiedBy = meetup;
meetup.self = meetup;
*/!*

alert( JSON.stringify(meetup, function replacer(key, value) {
/* your code */
}));

/* result should be:
{
"title":"Conference",
"occupiedBy":[{"name":"John"},{"name":"Alice"}],
"place":{"number":23}
}
*/
Expand Down
Loading
Toggle all file notes Toggle all file annotations