I have a string file like this

["ORM.mp4","bla.bla","blaa.blaa"]

an any body tell me how can I convert it to array of jSON object. I have tried various methods like json.stringify() then json.parse()etc. None of them worked.

Any help would be highly appreciated!

share|improve this question
    
objects have keys and values. what are your keys, and what are your values? – njzk2 23 hours ago
    
can you plz give an example – Asif Khan 23 hours ago
    
Share your desired output. – Hassan Imam 23 hours ago
up vote 0 down vote accepted
var test = '["ORM.mp4","bla.bla","blaa.blaa"]';
var data = JSON.parse(test);
console.log(data );

You can use JSON.parse() for parsing json.

share|improve this answer
    
it gives me error Unexpected token N in JSON at position 0 – Asif Khan 23 hours ago
    
I have just tried into console, it's running OK, let me know to code. and witch browser. – Chandraveer 22 hours ago

Use eval https://www.w3schools.com/jsref/jsref_eval.asp

 a = eval('["ORM.mp4","bla.bla","blaa.blaa"]')
 console.log(a)
share|improve this answer
var obj = ["ORM.mp4","bla.bla","blaa.blaa"].reduce(function(acc, cur, i) {
  acc[i] = cur;
  return acc;
}, {});
share|improve this answer
    
thanku your solutions also worked.. – Asif Khan 22 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.