Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
5.4k views
in Technique[技术] by (71.8m points)

Solve all json.decoder.JSONDecodeError in python

When I try to load data from excel using

 models = json.loads(my_column_with_JSon_data)["template"]["module"]

I get errors as:

  1. Expecting ',' delimiter: line 1 column 458 (char 457)
  2. json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 319 (char 318)
  3. json.decoder.JSONDecodeError: Expecting ':' delimiter: line 1 column 268 (char 267)

I understand there's a problem with my data, some delimiter missing, double quotes, etc and I saw there are different answers on stackoverflow according to each error on a specific set of data. That doesn't help me though - I can't manually modify my dataset since it is changing being scraped every time before using (different data). My question is: is there a way/formula/logic to use in order to solve this errors without manual modification of data?

One mention here: JSon data is scraped from web and comes in a correct format but after using Amazon Translation model, it gets modified. This code is used for translating the text:

for index, row in df3.iterrows():
        el1= row['col_1']
        tg = row['target']
        srs = row['source']
        text = row['to_be_translated']
        result = translate.translate_text(Text=text, SourceLanguageCode=sc,
                                       TargetLanguageCode=tg)
        tg_text = res.get('TranslatedText')
        tg_text = tg_text.replace('#- ', '#')
        content.append(
            {'col_1': el1,'source': srs, 'translated': text, 'target': tg,
             'translated_output': tg_text})

        output = dfFinalData.append(content)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...