@classmethod
    def set_field_value(cls, obj, field, value):
        if isinstance(value, basestring):
            value = value.strip()
        # try dict
        try:
            field, subfield = field.split(':')
        except Exception:
            pass
        else:
            field = field.strip()

            if field not in obj:
                obj[field] = {}

            cls.set_field_value(obj[field], subfield, value)
            return

        # try list
        try:
            field, _ = field.split()
        except Exception:
            pass
        else:
            dud = {}
            cls.set_field_value(dud, field, value)
            (field, value), = dud.items()

            if field not in obj:
                obj[field] = []
            elif not isinstance(obj[field], list):
                obj[field] = [obj[field]]
            if value not in (None, ''):
                obj[field].append(value)
            return

        # else flat

        # try boolean
        try:
            field, nothing = field.split('?')
            assert(nothing.strip() == '')
        except Exception:
            pass
        else:
            try:
                value = {
                    'yes': True,
                    'true': True,
                    'no': False,
                    'false': False,
                    '': False,
                    None: False,
                }[value.lower() if hasattr(value, 'lower') else value]
            except KeyError:
                raise JSONReaderError(
                    'Values for field %s must be "yes" or "no", not "%s"' % (
                        field, value)
                )

        # set for any flat type
        field = field.strip()
        if field in obj:
            raise JSONReaderError(
                'You have a repeat field: %s' % field
            )

        obj[field] = value
dataset/ETHPy150Open dimagi/commcare-hq/corehq/util/spreadsheets/excel.py/IteratorJSONReader.set_field_value/original