JavaScript Implementation
This module detects input documents with URI suffixes of the form “.1” and converts them into JSON documents with a “.json” URI extension. Note that the transform does not snoop the content to ensure it is actually JSON.
function modDocType(content, context) { var uri = String(content.uri); var dot = uri.lastIndexOf('.'); if (dot > 0) { var suffix = uri.slice(dot); if (suffix == '.1') { content.uri = uri.substring(0,dot+1) + 'json'; if (xdmp.nodeKind(content.value) == 'binary') { // convert the content to a JSON document content.value = xdmp.unquote(xdmp.quote(content.value)); } } } return content; }; exports.transform = modDocType;