Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print JSON data in console.log?

I cant access JSON data from javascript. Please help me how to access data from JSON data in javascript.

i have a JSON data like

{"success":true,"input_data":{"quantity-row_122":"1","price-row_122":" 35.1 "}} 

i have tried console.log(data) but log print object object

success:function(data){      console.log(data); } 

How to print console.log particular data? I need to print

quantity-row_122 = 1 price-row_122 = 35.1 
like image 617
Shojib Flamon Avatar asked Jan 26 '15 11:01

Shojib Flamon


People also ask

Can you console log JSON?

The console. log(JSON. stringify(obj)) method can be useful for logging the object to the console as string, as long as the data in the object is JSON-safe.

How do I view a JSON object in console log?

The simplest way is using the Console log() method to log objects as JSON in JavaScript. The console. log() method called with an object or objects as arguments will display the object or objects.


2 Answers

console.log(JSON.stringify(data)) will do what you need. I'm assuming that you're using jQuery based on your code.

If you're wanting those two particular values, you can just access those and pass them to log.

console.log(data.input_data['quantity-row_122']);  console.log(data.input_data['price-row_122']);  
like image 122
jdphenix Avatar answered Sep 24 '22 02:09

jdphenix


I used '%j' option in console.log to print JSON objects

console.log("%j", jsonObj); 
like image 44
Naren Chejara Avatar answered Sep 23 '22 02:09

Naren Chejara