This is because the AJAX request is asynchronous, so the return is hit before the call completes, so the function always returns null.
You need to call the code which relies on the AJAX call, from within the success call back itself. Try this:
function jsonServerResponse(operation, JSOoptionalData) {
JSOoptionalData = (typeof JSOoptionalData == "undefined") ? 'defaultValue' : JSOoptionalData
var jqxhr = $.ajax({
type: "POST",
url: "process.php",
data: "apicommand=" + JSOoptionalData,
success: function (json) {
alert("Response as JS Object: " + json);
// to see more information about the object returned, use console.log:
console.log(json);
}
});
}
jsonServerResponse("operation")