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!

hysabone.com
3,0552 gold badges18 silver badges26 bronze badges
asked Jan 5, 2018 at 6:05
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)
answered Jan 5, 2018 at 6:09
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.

answered Jan 5, 2018 at 6:12

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;
}, {});
answered Jan 5, 2018 at 6:09

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.