original_docstring: 
          Create JSON suitable for Wikibase API.
  
          When diffto is provided, JSON representing differences
          to the provided data is created.
  
          :param diffto: JSON containing entity data
          
docstring: Create JSON suitable for Wikibase API.
  When diffto is provided, JSON representing differences
  to the provided data is created.
docstring_tokens: Create JSON suitable for Wikibase API . When diffto is provided JSON representing differences to the provided data is created .
code: def toJSON(self, diffto: Optional[dict] = None) -> dict:
          """
          Create JSON suitable for Wikibase API.
  
          When diffto is provided, JSON representing differences
          to the provided data is created.
  
          :param diffto: JSON containing entity data
          """
          data = {dbname: sitelink.toJSON()
                  for (dbname, sitelink) in self.items()}
          if diffto:
              to_nuke = []
              for dbname, sitelink in data.items():
                  if dbname not in diffto:
                      continue
                  diffto_link = diffto[dbname]
                  if diffto_link.get('title') == sitelink.get('title'):
                      # compare badges
                      tmp_badges = []
                      diffto_badges = diffto_link.get('badges', [])
                      badges = sitelink.get('badges', [])
                      for badge in set(diffto_badges) - set(badges):
                          tmp_badges.append('')
                      for badge in set(badges) - set(diffto_badges):
                          tmp_badges.append(badge)
                      if tmp_badges:
                          data[dbname]['badges'] = tmp_badges
                      else:
                          to_nuke.append(dbname)
  
              # find removed sitelinks
              for dbname in (set(diffto.keys()) - set(self.keys())):
                  badges = [''] * len(diffto[dbname].get('badges', []))
                  data[dbname] = {'site': dbname, 'title': ''}
                  if badges:
                      data[dbname]['badges'] = badges
              for dbname in to_nuke:
                  del data[dbname]
          return data
code_tokens: def toJSON ( self , diffto : Optional [ dict ] = None ) -> dict : data = { dbname : sitelink . toJSON ( ) for ( dbname , sitelink ) in self . items ( ) } if diffto : to_nuke = [ ] for dbname , sitelink in data . items ( ) : if dbname not in diffto : continue diffto_link = diffto [ dbname ] if diffto_link . get ( 'title' ) == sitelink . get ( 'title' ) : tmp_badges = [ ] diffto_badges = diffto_link . get ( 'badges' , [ ] ) badges = sitelink . get ( 'badges' , [ ] ) for badge in set ( diffto_badges ) - set ( badges ) : tmp_badges . append ( '' ) for badge in set ( badges ) - set ( diffto_badges ) : tmp_badges . append ( badge ) if tmp_badges : data [ dbname ] [ 'badges' ] = tmp_badges else : to_nuke . append ( dbname ) for dbname in ( set ( diffto . keys ( ) ) - set ( self . keys ( ) ) ) : badges = [ '' ] * len ( diffto [ dbname ] . get ( 'badges' , [ ] ) ) data [ dbname ] = { 'site' : dbname , 'title' : '' } if badges : data [ dbname ] [ 'badges' ] = badges for dbname in to_nuke : del data [ dbname ] return data
short_docstring: Create JSON suitable for Wikibase API.
short_docstring_tokens: Create JSON suitable for Wikibase API .
comment: """
          Create JSON suitable for Wikibase API.
  
          When diffto is provided, JSON representing differences
          to the provided data is created.
  
          :param diffto: JSON containing entity data
          """$SEP$# compare badges$SEP$# find removed sitelinks