Skip to content

Instantly share code, notes, and snippets.

@lmatteis
Last active December 14, 2015 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmatteis/5013182 to your computer and use it in GitHub Desktop.
Save lmatteis/5013182 to your computer and use it in GitHub Desktop.
RDFtoJSONP
function doGet(e) {
var url = e.parameter.url;
var content = UrlFetchApp.fetch(url).getContentText();
var jsonString = JSON.stringify(content);
return ContentService.createTextOutput()
.setMimeType(ContentService.MimeType.JSON)
.setContent(e.parameter.callback + '(' + jsonString + ');');
}
@lmatteis
Copy link
Author

  1. Go to http://script.google.com
  2. Create a new Script (as a web app) and then copy and paste this code (replacing the current stuff you find there).
  3. Click on File->Manage Version, and create a new version.
  4. Then go to Publish->Deploy as web app.. and deploy the version you just created in the earlier step.
  5. You'll get an url similar to: https://script.google.com/macros/s/AKF..../exec
  6. To use it, simply append the parameter ?url=http://example.com/ontology#termName to the end of this url.
  7. And to use it as JSONP, also add a &callback=foo paramater.

For example, with jQuery you could use this as:

$.getJSON('https://script.google.com/macros/s/AKF..../exec?url=http://example.com/ontology#termName&callback=?', function(data) {
    console.log(data);
});

note remember to replace the App Script URL (https://script.google.com/macros/s/AKF..../exec) with your own Apps Script URL .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment