{
  "@context":"https://www.w3.org/ns/activitystreams",
  <%- if recursive == true && (first = collection.first?) -%>
  "first":<%= first.to_json_ld %>,
  <%- elsif (first_iri = collection.first_iri) -%>
  "first":<%= first_iri.to_json %>,
  <%- end -%>
  <%- if recursive == true && (last = collection.last?) -%>
  "last":<%= last.to_json_ld %>,
  <%- elsif (last_iri = collection.last_iri) -%>
  "last":<%= last_iri.to_json %>,
  <%- end -%>
  <%- if recursive == true && (prev = collection.prev?) -%>
  "prev":<%= prev.to_json_ld %>,
  <%- elsif (prev_iri = collection.prev_iri) -%>
  "prev":<%= prev_iri.to_json %>,
  <%- end -%>
  <%- if recursive == true && (_next = collection.next?) -%>
  "next":<%= _next.to_json_ld %>,
  <%- elsif (next_iri = collection.next_iri) -%>
  "next":<%= next_iri.to_json %>,
  <%- end -%>
  <%- if recursive == true && (current = collection.current?) -%>
  "current":<%= current.to_json_ld %>,
  <%- elsif (current_iri = collection.current_iri) -%>
  "current":<%= current_iri.to_json %>,
  <%- end -%>
  <%- if (total_items = collection.total_items) -%>
  "totalItems":<%= total_items %>,
  <%- end -%>
  <%- if recursive == true && (items = collection.items) -%>
  "items":[
  <%- items.each.with_index do |item, i| -%>
  <%- if item.responds_to?(:to_json_ld) && item.responds_to?(:local?) && item.local? -%>
  <%= item.to_json_ld %>
  <%- elsif item.responds_to?(:iri) -%>
  <%= item.iri.to_json %>
  <%- elsif item.is_a?(String) -%>
  <%= item.to_json %>
  <%- end -%><%= comma(items, i) %>
  <%- end -%>
  ],
  <%- elsif (iris = collection.items_iris) -%>
  "items":[
  <%- iris.each.with_index do |iri, i| -%>
  <%= iri.to_json %><%= comma(iris, i) %>
  <%- end -%>
  ],
  <%- end -%>
  "type":<%= collection.class.to_s.split("::").last.to_json %>,
  "id":<%= collection.iri.to_json %>
}
