Total Post:12

 2102  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.

  1. Post:604

    Re: Send JSON Data for Debugging


    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



Enter your email address here always to be updated. We promise not to spam!