Error Parsing JSON giving unexpected token o error

0 votes

I am having a problem parsing simple JSON strings. I have checked them on JSONLint and it shows that they are valid. But when I try to parse them using either JSON.parse or the jQuery alternative it gives me the error unexpected token o:

<!doctype HTML>
<html>
  <head>
  </head>
  <body>
    <script type="text/javascript">
      var cur_ques_details ={"ques_id":15,"ques_title":"jlkjlkjlkjljl"};
      var ques_list = JSON.parse(cur_ques_details);

      document.write(ques_list['ques_title']);
    </script>
  </body>
</html>

How to solve this error?

Jun 19, 2020 in Java-Script by kartik
• 37,490 points
577 views

1 answer to this question.

0 votes

Hello @kartik,

Your data is already an object. No need to parse it.

 The javascript interpreter has already parsed it for you.

var cur_ques_details ={"ques_id":15,"ques_title":"jlkjlkjlkjljl"};
document.write(cur_ques_details['ques_title']);

Hope it is helpful!

Thank you!!

answered Jun 19, 2020 by Niroj
• 82,540 points

@Kartik,

Niroj has mentioned perfectly. It's already parsed and ready to use as JSON Object. in case if you want to see the full code. it will look like this.

<!doctype HTML>
<html>
  <head>
  </head>
  <body>
      var cur_ques_details ={"ques_id":15,"ques_title":"jlkjlkjlkjljl"};
      document.write(cur_ques_details['ques_title']);
  </body>
</html>
I have developed this tool using this concept. https://jsonformatter.org/json-pretty-print
I hope it helps. Thanks Niroj to point out the perfect answer.

You don't need to parse JSON anymore

 

Related Questions In Java-Script

0 votes
1 answer

Error:jQuery.parseJSON throws “Invalid JSON” error due to escaped single quote in JSON

Hello @kartik, Striking a similar issue using CakePHP ...READ MORE

answered Jun 19, 2020 in Java-Script by Niroj
• 82,540 points
1,309 views
0 votes
1 answer

Error:Failed to load resource: net::ERR_FILE_NOT_FOUND loading json.js

Hii @kartik,  got the same error using: <link rel="stylesheet" ...READ MORE

answered Jun 19, 2020 in Java-Script by Niroj
• 82,540 points
4,754 views
0 votes
1 answer

How can we parse JSON using Node.js?

Hello @kartik, You can simply use JSON.parse. The definition of ...READ MORE

answered Apr 24, 2020 in Java-Script by Niroj
• 82,540 points
104 views
0 votes
1 answer

How to print a circular structure in a JSON-like format?

Hello, You can use util.inspect(object) in node.js. It automatically ...READ MORE

answered Apr 24, 2020 in Java-Script by Niroj
• 82,540 points
570 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,540 points
4,775 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,540 points
538 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,540 points
406 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,540 points
5,394 views
0 votes
1 answer

Error: Unexpected token import in nodejs

Hello, Unfortunately, Node.js doesn't support ES6's import yet. To accomplish what ...READ MORE

answered Apr 24, 2020 in Java-Script by Niroj
• 82,540 points
4,045 views
0 votes
1 answer

Error:Uncaught SyntaxError: Unexpected token

Hello @kartik, Using the jQuery command getJSON and ...READ MORE

answered Oct 9, 2020 in Java-Script by Niroj
• 82,540 points
479 views