0

I'm getting some errors from my backend which look similar to:

'errors': {
  'something.937db262-657c-4676-9526-c550dcb922d7.field1': ['Invalid value'],
  'something.937db262-657c-4676-9526-c550dcb922d7.field2': ['Invalid value', 'text too short'],
  'something.10411657-1947-49cc-ab9c-029163aeff85.field1': ['some other error']
}

But how do I convert it to this:

'errors': {
  'something': {
    '937db262-657c-4676-9526-c550dcb922d7': {
      'field1': ['Invalid value'],
      'field2': ['Invalid value', 'text too short']
    },
    '10411657-1947-49cc-ab9c-029163aeff85.field3' : {
      'field1': ['some other error']
    }
  }
}

I tried a lot of things but didn't get it to work yet.

Thank you!

Pinnokkio
  • 359
  • 1
  • 2
  • 9
  • Can you post your attempt so far? It would be helpful to have some code to work from. For example, maybe you already have something that iterates over the `errors`, but isn't mutating properly, then we could help with a more specific issue. – CollinD Apr 20 '22 at 00:16
  • Related: https://stackoverflow.com/questions/26908996/create-objects-dynamically-out-of-a-dot-notation-like-string https://stackoverflow.com/questions/14891040/create-an-object-out-of-dot-notation https://stackoverflow.com/questions/49047845/how-to-turn-dot-notation-string-into-an-object-in-javascript – SuperStormer Apr 20 '22 at 00:17

0 Answers0