diff --git a/app/api/utils.py b/app/api/utils.py index f40a0137..afddcfae 100644 --- a/app/api/utils.py +++ b/app/api/utils.py @@ -222,6 +222,10 @@ class FileParser(object): def parse(self, file): raise NotImplementedError() + @staticmethod + def encode_metadata(data): + return json.dumps(data, ensure_ascii=False) + class CoNLLParser(FileParser): """Uploads CoNLL format file. @@ -358,7 +362,7 @@ class ExcelParser(FileParser): elif len(row) == len(columns) and len(row) >= 2: datum = dict(zip(columns, row)) text, label = datum.pop('text'), datum.pop('label') - meta = json.dumps(datum) + meta = FileParser.encode_metadata(datum) j = {'text': text, 'labels': [label], 'meta': meta} data.append(j) else: @@ -379,7 +383,7 @@ class JSONParser(FileParser): data = [] try: j = json.loads(line) - j['meta'] = json.dumps(j.get('meta', {})) + j['meta'] = FileParser.encode_metadata(j.get('meta', {})) data.append(j) except json.decoder.JSONDecodeError: raise FileParseException(line_num=i, line=line)