I am attempting to make server side calls to restful API's using node.js. Returns with JSONP (JSON container inside a JS function) are returning errors that seems to be at the heart of the node http.get(options, callback) API. Can node or any module return the JSON object from a JSONP return?
Example JSONP request: http://www.linkedin.com/countserv/count/share?url=http://techcrunch.com/2012/01/29/turning-two-founderscard-pulls-back-the-curtain-on-its-membership-community-for-entrepreneurs/
Execute the callback with vm
JavaScript code can be compiled and run immediately or compiled, saved, and run later
A previous answer suggests striping the callback function. Unfortunately, this is not compatible with many jsonp responses since the contents of the function are usually objects and not pure JSON. The JSON.parse() function will die for something like the following:
callback({key:"value"});
While the above is a valid object, it is not valid JSON.
The following will execute the callback and return the object:
jsonpSandbox = vm.createContext({callback: function(r){return r;}});
myObject = vm.runInContext(jsonpData,jsonpSandbox);
When creating the context change callback
to the name of the callback function that is returned in the jsonp response.