Code Lab

JSON there and back

EasyJSON 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.

Examples

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

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

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

Source

Loading the editor...
  1. InputjsonRoundTrip({ name: 'John', age: 35 })
    Expected{ json: '{"name":"John","age":35}', copy: { name: 'John', age: 35 } }
  2. copy equals user, but it is a different object

Hidden tests run on Submit.