0

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!

3
  • objects have keys and values. what are your keys, and what are your values? Commented Jan 5, 2018 at 6:08
  • can you plz give an example Commented Jan 5, 2018 at 6:08
  • Share your desired output. Commented Jan 5, 2018 at 6:09

3 Answers 3

1

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

 a = eval('["ORM.mp4","bla.bla","blaa.blaa"]')
 console.log(a)
Sign up to request clarification or add additional context in comments.

Comments

0
var test = '["ORM.mp4","bla.bla","blaa.blaa"]';
var data = JSON.parse(test);
console.log(data );

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

2 Comments

it gives me error Unexpected token N in JSON at position 0
I have just tried into console, it's running OK, let me know to code. and witch browser.
0
var obj = ["ORM.mp4","bla.bla","blaa.blaa"].reduce(function(acc, cur, i) {
  acc[i] = cur;
  return acc;
}, {});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.