-1

How can I use destructuring to create a new object that deep copies this:

{
  "data": [
    {
      "type": "b",
      "id": "2",
      "other": {
        "name": "hello"
      }
    }
  ]
}

and spits out one of these:

{
  "data": {
      "type": "b",
      "id": "2",
      "other": {
        "name": "hello"
      }
    }
  }
}
Mike
  • 609
  • 12
  • 36

1 Answers1

2

This is super simple, but I think this is what you are looking for:

output = { data: JSON.parse(JSON.stringify(input.data[0])) }

This should deep copy it, but it will remove all types that cannot be stringified into JSON.