1

i have this array

"[{\"category_id\":\"2\",\"category_name\":\"Fun\"},
{\"category_id\":\"3\",\"category_name\":\"Science\"},
 {\"category_id\":\"4\",\"category_name\":\"Art\"},
{\"category_id\":\"5\",\"category_name\":\"Nature\"},...]"

i want to output this in user readable format

4
  • Put your code structure here then we can help you. Commented Oct 28, 2017 at 19:01
  • It is not an array. It’s a string Commented Oct 28, 2017 at 19:02
  • 1
    Possible duplicate of Remove Backslashes from Json Data in JavaScript Commented Oct 28, 2017 at 19:05
  • what does "user readable format" mean to you? Do you want us to just guess? Commented Oct 28, 2017 at 19:27

2 Answers 2

1

It’s not an array. It’s a string.

Perhaps you mean

var x = "[{\"category_id\":\"2\",\"category_name\":\"Fun\"},{\"category_id\":\"3\",\"category_name\":\"Science\"},{\"category_id\":\"4\",\"category_name\":\"Art\"},{\"category_id\":\"5\",\"category_name\":\"Nature\"}]"

console.log(JSON.stringify(JSON.parse(x)))
Sign up to request clarification or add additional context in comments.

Comments

0

Try below code.

   var obj = "[{\"category_id\":\"2\",\"category_name\":\"Fun\"},{\"category_id\":\"3\",\"category_name\":\"Science\"},{\"category_id\":\"4\",\"category_name\":\"Art\"},{\"category_id\":\"5\",\"category_name\":\"Nature\"},...]";

    obj = obj.replace(/\\/g, '');
    console.log(obj);

Comments

Your Answer

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.