@staticmethod
    def build_json_resource_obj(fields, resource, resource_instance, resource_name):
        resource_data = [
            ('type', resource_name),
            ('id', encoding.force_text(resource_instance.pk) if resource_instance else None),
            ('attributes', JSONRenderer.extract_attributes(fields, resource)),
        ]
        relationships = JSONRenderer.extract_relationships(fields, resource, resource_instance)
        if relationships:
            resource_data.append(('relationships', relationships))
        # Add 'self' link if field is present and valid
        if api_settings.URL_FIELD_NAME in resource and \
                isinstance(fields[api_settings.URL_FIELD_NAME], relations.RelatedField):
            resource_data.append(('links', {'self': resource[api_settings.URL_FIELD_NAME]}))
        return OrderedDict(resource_data)
dataset/ETHPy150Open django-json-api/django-rest-framework-json-api/rest_framework_json_api/renderers.py/JSONRenderer.build_json_resource_obj/original