Code Lab

Mode entretien. Minuteur de 3 min, sans indices ni autocomplétion

JSON there and back

FacileJSON and data3 min

Write a function jsonRoundTrip(user). It turns the object user into a JSON string and then parses that string back into a new object. Return { json, copy } with the string and the object made from it.

Exemples

jsonRoundTrip({ name: 'John', age: 35 })

Renvoie { json: '{"name":"John","age":35}', copy: { name: 'John', age: 35 } }

The JSON string has no spaces, and the keys are in double quotes.

Source

Chargement de l'éditeur...
  1. EntréejsonRoundTrip({ name: 'John', age: 35 })
    Attendu{ json: '{"name":"John","age":35}', copy: { name: 'John', age: 35 } }
  2. copy equals user, but it is a different object

Les tests cachés se lancent à la soumission