0

I have a string, which looks like that:

"{ dataField: 'id', allowEditing: false },{ dataField: 'customer', allowEditing: false },{ dataField: 'type', allowEditing: false },{ dataField: 'weightMax', allowEditing: false },{ dataField: 'weightMin', allowEditing: false }"

I'm wondering about the way to parse this string to array of objects. The result I'm expecting is an array which looks like that:

[{ dataField: 'id', allowEditing: false }, { dataField: 'customer', allowEditing: false }, { dataField: 'type' }, { dataField: 'weightMax' }, { dataField: 'weightMin'}]

Thanks in advance!!

Szacharz
  • 15
  • 3
  • 3
    If your string were standard JSON, it would be easy. However, it is not. – Pointy May 18 '22 at 11:56
  • 1
    You could use [`eval`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) or [`Function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Function), but usually you shouldn't – jabaa May 18 '22 at 12:04
  • There are a few options outlined [here](https://stackoverflow.com/q/54868074/5648954) (option 1 is preferred). – Nick Parsons May 18 '22 at 12:06

0 Answers0