Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prototype has hash.inspect() method. What is the equivalent in jQuery world?

Tags:

jquery

I am using jQuery. I am dealing with JSON object and time and again I need to look at the data. I do alert(data) and I get nothing useful.

In the Prototype world they have inspect method which is highly useful. inspect method in Prototype

I am looking for equivalent method in jQuery. I looked at the API and couldn't find anything. I am sure someone would have developed some plugin to solve this problem.

like image 310
Neeraj Singh Avatar asked Jun 10 '09 14:06

Neeraj Singh


2 Answers

You can use the jQuery.param function, which will format it into a querystring format.

alert(jQuery.param({ width:1680, height:1050 }));
// shows "width=1680&height=1050"
like image 146
bdukes Avatar answered Nov 07 '22 19:11

bdukes


I have the best result with http://www.JSON.org/json2.js. As the docs say:

    JSON.stringify(value, replacer, space)
        value       any JavaScript value, usually an object or array.

        replacer    an optional parameter that determines how object
                    values are stringified for objects. It can be a
                    function or an array of strings.

        space       an optional parameter that specifies the indentation
                    of nested structures. If it is omitted, the text will
                    be packed without extra whitespace. If it is a number,
                    it will specify the number of spaces to indent at each
                    level. If it is a string (such as '\t' or ' '),
                    it contains the characters used to indent at each level.

Just include the library and call alert(JSON.stringify(data)) to see a legible representation of your object.

like image 7
edavey Avatar answered Nov 07 '22 17:11

edavey