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,520 points
3,427 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,840 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>

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,840 points
5,113 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,840 points
20,107 views
0 votes
0 answers

Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>)

I was trying to change a string ...READ MORE

May 9, 2022 in Java-Script by Kichu
• 19,040 points
6,865 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,840 points
832 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,840 points
23,059 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,840 points
3,013 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,840 points
2,937 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,840 points
44,853 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,840 points
9,343 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,840 points
3,817 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP