def convertInstagramJSONToItem(inst, partial):
    """
    Convert an instagram JSON object to our item format.

    :param inst: the instagram item.
    :param partial: if True, partial data is allowed.
    :return: an item or None.
    """
    if (not inst.get('location', None) or
            'latitude' not in inst['location'] or
            'longitude' not in inst['location']):
        return None
    item = {
        'user_name':     inst['user']['username'],
        'user_fullname': inst['user']['full_name'],
        'user_id':       inst['user']['id'],
        'posted_date':   inst['created_time'],
        'url':           inst['link'],
        'latitude':      inst['location']['latitude'],
        'longitude':     inst['location']['longitude'],
        'comment_count': inst['comments']['count'],
        'comments':      '',
        'like_count':    inst['likes']['count'],
        'likes':         '',
        'scraped_date':  int(inst['created_time']),
        'msg_id':        inst['link'].rsplit('/', 1)[-1]
    }
    if inst['caption']:
        item['caption'] = inst['caption']['text']
        item['scraped_date'] = max(item['scraped_date'],
                                   int(inst['caption'].get('created_time', 0)))
    if 'data' in inst['comments']:
        for comm in inst['comments']['data']:
            item['scraped_date'] = max(
                item['scraped_date'],
                int(comm.get('created_time', 0)))
    if not partial:
        if 'id' in inst['location']:
            item['location_id'] = inst['location']['id']
        if 'name' in inst['location']:
            item['location_name'] = inst['location']['name']
        if 'data' in inst['comments']:
            item['comments'] = '|'.join(['%s;%s;%s;%s' % (
                comm['from']['username'], comm['from']['id'],
                comm['created_time'], comm['text'].replace('|', ' ')
            ) for comm in inst['comments']['data']])
        if 'data' in inst['likes']:
            item['likes'] = '|'.join(['%s;%s' % (
                like['username'], like['id']
            ) for like in inst['likes']['data']])
    return item