0

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 Answers1

1

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

RandomSlav
  • 507
  • 3
  • 13
  • Thanks... but I have tried this method... doesn't work !! And I'm getting this string from the database, which is not in my control...Can you help with another method ? – Prince Gajjar Apr 14 '22 at 13:37
  • In Fiddle it [works](https://jsfiddle.net/x2tzagfn/). Are you sure that this is the string format you get from database? – RandomSlav Apr 14 '22 at 13:39
  • 1
    Thank you so much... @RandomSlav. It works. All I needed to change from ```eval('(' + str + ')');``` to ```eval('[' + str + ']');```. – Prince Gajjar Apr 15 '22 at 04:45