code: def as_json(self, validate=True):
          
          if (validate):
              self.validate()
          json_dict = {}
          if (self.api_version > '1.0'):
              json_dict['@context'] = self.context
          params_to_write = set(self.params)
          params_to_write.discard('identifier')
          if (self.identifier):
              if (self.api_version == '1.0'):
                  json_dict['identifier'] = self.identifier  # local id
              else:
                  json_dict['@id'] = self.id  # URI
          params_to_write.discard('profile')
          if (self.compliance):
              if (self.api_version < '2.0'):
                  json_dict['profile'] = self.compliance
              else:
                  # FIXME - need to support extra profile features
                  json_dict['profile'] = [self.compliance]
                  d = {}
                  if (self.formats is not None):
                      d['formats'] = self.formats
                  if (self.qualities is not None):
                      d['qualities'] = self.qualities
                  if (self.supports is not None):
                      d['supports'] = self.supports
                  if (len(d) > 0):
                      json_dict['profile'].append(d)
                  params_to_write.discard('formats')
                  params_to_write.discard('qualities')
                  params_to_write.discard('supports')
          for param in params_to_write:
              if (hasattr(self, param) and
                      getattr(self, param) is not None):
                  json_dict[param] = getattr(self, param)
          return(json.dumps(json_dict, sort_keys=True, indent=2))
docs: Return JSON serialization.
  
          Will raise IIIFInfoError if insufficient parameters are present to
          have a valid info.json response (unless validate is False).