tasks/jsonld/js/jsonld.js
function _RDFToObject(o, useNativeTypes) {
  // convert IRI/blank node object to JSON-LD
  if(o.type === 'IRI' || o.type === 'blank node') {
    return {'@id': o.value};
  }

  // convert literal to JSON-LD
  var rval = {'@value': o.value};

  // add language
  if('language' in o) {
    rval['@language'] = o.language;
  }
  // add datatype
  else {
    var type = o.datatype;
    // use native types for certain xsd types
    if(useNativeTypes) {
      if(type === XSD_BOOLEAN) {
        if(rval['@value'] === 'true') {
          rval['@value'] = true;
        }
        else if(rval['@value'] === 'false') {
          rval['@value'] = false;
        }
      }
      else if(_isNumeric(rval['@value'])) {
        if(type === XSD_INTEGER) {
          var i = parseInt(rval['@value']);
          if(i.toFixed(0) === rval['@value']) {
            rval['@value'] = i;
          }
        }
        else if(type === XSD_DOUBLE) {
          rval['@value'] = parseFloat(rval['@value']);
        }
      }
      // do not add native type
      if([XSD_BOOLEAN, XSD_INTEGER, XSD_DOUBLE, XSD_STRING]
        .indexOf(type) === -1) {
        rval['@type'] = type;
      }
    }
    else if(type !== XSD_STRING) {
      rval['@type'] = type;
    }
  }

  return rval;
}
function _RDFToObject(o, useNativeTypes) {
  // convert IRI/blank node object to JSON-LD
  if(o.type === 'IRI' || o.type === 'blank node') {
    return {'@id': o.value};
  }

  // convert literal to JSON-LD
  var rval = {'@value': o.value};

  // add language
  if('language' in o) {
    rval['@language'] = o.language;
  }
  // add datatype
  else {
    var type = o.datatype;
    // use native types for certain xsd types
    if(useNativeTypes) {
      if(type === XSD_BOOLEAN) {
        if(rval['@value'] === 'true') {
          rval['@value'] = true;
        }
        else if(rval['@value'] === 'false') {
          rval['@value'] = false;
        }
      }
      else if(_isNumeric(rval['@value'])) {
        if(type === XSD_INTEGER) {
          var i = parseInt(rval['@value']);
          if(i.toFixed(0) === rval['@value']) {
            rval['@value'] = i;
          }
        }
        else if(type === XSD_DOUBLE) {
          rval['@value'] = parseFloat(rval['@value']);
        }
      }
      // do not add native type
      if([XSD_BOOLEAN, XSD_INTEGER, XSD_DOUBLE, XSD_STRING]
        .indexOf(type) === -1) {
        rval['@type'] = type;
      }
    }
    else if(type !== XSD_STRING) {
      rval['@type'] = type;
    }
  }

  return rval;
}
function _RDFToObject ( o , useNativeTypes ) { // convert IRI/blank node object to JSON-LD if ( o . type === 'IRI' || o . type === 'blank node' ) { return { '@id' : o . value } ; } // convert literal to JSON-LD var rval = { '@value' : o . value } ; // add language if ( 'language' in o ) { rval [ '@language' ] = o . language ; } // add datatype else { var type = o . datatype ; // use native types for certain xsd types if ( useNativeTypes ) { if ( type === XSD_BOOLEAN ) { if ( rval [ '@value' ] === 'true' ) { rval [ '@value' ] = true ; } else if ( rval [ '@value' ] === 'false' ) { rval [ '@value' ] = false ; } } else if ( _isNumeric ( rval [ '@value' ] ) ) { if ( type === XSD_INTEGER ) { var i = parseInt ( rval [ '@value' ] ) ; if ( i . toFixed ( 0 ) === rval [ '@value' ] ) { rval [ '@value' ] = i ; } } else if ( type === XSD_DOUBLE ) { rval [ '@value' ] = parseFloat ( rval [ '@value' ] ) ; } } // do not add native type if ( [ XSD_BOOLEAN , XSD_INTEGER , XSD_DOUBLE , XSD_STRING ] . indexOf ( type ) === - 1 ) { rval [ '@type' ] = type ; } } else if ( type !== XSD_STRING ) { rval [ '@type' ] = type ; } } return rval ; }
Converts an RDF triple object to a JSON-LD object.

@param o the RDF triple object to convert.
@param useNativeTypes true to output native types, false not to.

@return the JSON-LD object.
Converts an RDF triple object to a JSON - LD object .