Getting error in filter initialization in query builder

146 views Asked by At

I am getting a string like this

 "{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']},{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']}";

I can also put this in an object like this

obj : [ "{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']},{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']}";]

Problem is, filter of query builder can't read the value of this object because of those double quotes (") after and before square braces ([)

I just want to remove those double quotes from and object. So filter can read out object properly. So is there any method in javascript or c# to do this ?

My expected output is :

obj : [ {id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']},{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']}]
1

There are 1 answers

3
RandomSlav On

let str = "{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']},{id: 'breakthrough_designation_y_n',label: 'Breakthrough Designation Y/N',type: 'string',input: 'radio',values:{'Yes': 'Yes','No': 'No'},operators: ['equal']}";

let obj = eval('(' + str + ')');
console.log(obj);

As a note - the string is weird, usually there are quotes around properties. See W3 Schools JSON Introduction