Q:

How to load JSON from variable, object

I have this code:
var browserName = "chrome";

    function getBrowserHack() {

        var browsersStack = {
            "chrome" : {
                "hacks": {
                    "global" : "!! window.chrome;",
                    "version" : {
                        "32" : "!! window.chrome && !! window.chrome.webstore;"
                    }
                }
            },
            "firefox" : {
                "hacks": {
                    "global" : "!! window.sidebar;",
                    "version" : {
                        "2": "(function x(){})[-6]=='x';"
                    }
                }
            },
            "safari" : {
                "hacks" : {
                    "global" : "/constructor/i.test(window. HTMLElement);"
                }
            },
            "opera" : {
                "hacks" : {
                    "global" : "window.opera && window.opera.version() == X;"
                }
            }
        }
        return $.getJSON(browsersStack, function(data){
            var browsers = data[browserName];
            return browsers;
        });
    }

i need to return function with this JSON data, and i have an error [object%20Object] 404 (Not Found).  What i'm doing wrong?  

A:

I think you misunderstood getJSON, you have the JS Object already right there in your code, try this:
function getBrowserHack(browserName) {

    var browsersStack = {
        "chrome" : {
            "hacks": {
                "global" : "!! window.chrome;",
                "version" : {
                    "32" : "!! window.chrome && !! window.chrome.webstore;"
                }
            }
        },
        "firefox" : {
            "hacks": {
                "global" : "!! window.sidebar;",
                "version" : {
                    "2": "(function x(){})[-6]=='x';"
                }
            }
        },
        "safari" : {
            "hacks" : {
                "global" : "/constructor/i.test(window. HTMLElement);"
            }
        },
        "opera" : {
            "hacks" : {
                "global" : "window.opera && window.opera.version() == X;"
            }
        }
    }
    return browsersStack[browserName];
}

// Now get the browserhack by calling:
var browserHack = getBrowserHack('chrome');

