You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: document.go
    path of file: ./repos/moby/vendor/github.com/spdx/tools-golang/spdx/v2/v2_2
    
    the code of the file until where you have to start completion: // Package spdx contains the struct definition for 
    
func (d *Document) UnmarshalJSON(b []byte) error {
	type doc Document
	type extras struct {
		DocumentDescribes []common.DocElementID `json:"documentDescribes"`
	}

	var d2 doc
	if err := json.Unmarshal(b, &d2); err != nil {
		return err
	}

	var e extras
	if err := json.Unmarshal(b, &e); err != nil {
		return err
	}

	*d = Document(d2)

	relationshipExists := map[string]bool{}
	serializeRel := func(r *Relationship) string {
		refA := r.RefA
		refB := r.RefB
		rel := r.Relationship

		// we need to serialize the opposite for CONTAINED_BY and DESCRIBED_BY
		// so that it will match when we try to de-duplicate during deserialization.
		switch r.Relationship {
		case common.TypeRelationshipContainedBy:
			rel = common.TypeRelationshipContains
			refA = r.RefB
			refB = r.RefA
		case common.TypeRelationshipDescribeBy:
			rel = common.TypeRelationshipDescribe
			refA = r.RefB
			refB = r.RefA
		}
		return fmt.Sprintf("%v-%v->%v", common.RenderDocElementID(refA), rel, common.RenderDocElementID(refB))
	}

	// index current list of relationships to ensure no duplication
	for _, r := range d.Relationships {
		relationshipExists[serializeRel(r)] = true
	}

	// build relationships for documentDescribes field
	for _, id := range e.DocumentDescribes {
		r := &Relationship{
			RefA: common.DocElementID{
				ElementRefID: d.SPDXIdentifier,
			},
			RefB:         id,
			Relationship: common.TypeRelationshipDescribe,
		}

		if !relationshipExists[serializeRel(r)] {
			d.Relationships = append(d.Relationships, r)
			relationshipExists[serializeRel(r)] = true
		}
	}

	// build relationships for package hasFiles field
	for _, p := range d.Packages {
		for _, f := range p.hasFiles {
			r := &Relationship{
				RefA: common.DocElementID{
					ElementRefID: p.PackageSPDXIdentifier,
				},
				RefB:         f,
				Relationship: common.TypeRelationshipContains,
			}
			if !relationshipExists[serializeRel(r)] {
				d.Relationships = append(d.Relationships, r)
				relationshipExists[serializeRel(r)] = true
			}
		}

		p.hasFiles = nil
	}

	return nil
}