Code Lab

Modo entrevista. Temporizador de 3 min, sin pistas y sin autocompletado

JSON there and back

FácilJSON 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.

Ejemplos

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

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

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

Fuente

Cargando el editor…
  1. EntradajsonRoundTrip({ name: 'John', age: 35 })
    Esperado{ json: '{"name":"John","age":35}', copy: { name: 'John', age: 35 } }
  2. copy equals user, but it is a different object

Las pruebas ocultas se ejecutan al enviar