Home > DeveloperSection > Forums > Send JSON Data for Debugging
Hank Greenberg
Hank Greenberg

Total Post:12

Points:84
Posted on    June-20-2013 3:29 AM

 JSON JSON 
Ratings:


 1 Reply(s)
 1253  View(s)
Rate this:
Hi Developers,

I would like to debug client side applications by manually creating a JSON data stream. I was hoping that Google Chrome's debug console would be able to do this.

For example, consider the following case. I want to test how a list population code segment would work. Let's say I have item objects of the format: {"name" : "test", "price" : "10"}. Instead of actually coding this up on the server, I would like to generate this data locally and send it for testing purposes.

The Javascript would look something like this:

//JQuery AJAX call to request data
$.getJSON('some_url', function(data) {

     //Go through each received JSON element (assuming array input) and
     //log its key value pair to the debug console (using Google Chrome as example)
     $.each(data, function(key, val) {
          console.log("Key is: " + key + " value is: " + value);
     }

});//End getJSON

I would want to make a list of data (perhaps in a text file?) like so:

{"name" : "paper", "price" : "5"}
{"name" : "bear repellent", "price" : "10"}

I would then like to pass this data into the function to see if it works and see the output (accomplished here by the console.log() call). I understand that this is somewhat like unit testing, and my research indicates that this might be the job for a REST client. However, I am unsure how to accomplish this. Input is appreciated.



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    June-20-2013 7:48 AM

Hi,

simply create a js file in the following format

var tempData = [
   {name : "paper", price : 5},
   {name : "bear repellent", price : 10},
];

Add this file to your page using <script> tag

Then use the tempData object as data in your function call

Don't want to miss updates? Please click the below button!

Follow MindStick