You nailed the problem, ajax is an async operation, you can use the returned data only in the success callback:
function jsonServerResponse(operation, JSOoptionalData) {
// What that line suppose to do???
JSOoptionalData = (typeof JSOoptionalData == "undefined") ? 'defaultValue' : JSOoptionalData
var jqxhr = $.ajax({
type: "POST",
url: "process.php",
data: "apicommand=" + JSOoptionalData,
dataType: "json", // Change the dataType to json.
success: function (json) {
console.log("Response as JS Object:")
console.log(json);
}
});
}