chat-analytics icon indicating copy to clipboard operation
chat-analytics copied to clipboard

Telegram parse error

Open thesingodim opened this issue 2 years ago • 4 comments

Error parsing file "result.json":

JSON.parse: bad escaped character at line 33 column 17 of the JSON data error

Solution: I exported from telegram group history (129mb) in result.json, then replaced some bad characters with python:

with open('result.json', encoding='utf-8') as f:
    result = f.read()

result  = result.replace('\\x0C','').replace('\\x00','').replace('\\x10','').replace('\\x11','').replace('\\x08','').replace('\\x01','')

with open('r.json','w+', encoding='utf-8') as f:
    f.write(result)```

And now it works! Seems like telegram inserts some bad characters into .json
Thank you for huge work!

thesingodim avatar Dec 30 '23 06:12 thesingodim

I don't personally use Telegram so maybe this is a thing that happens in all new exports and I wouldn't know, but in case it isn't it might be useful to have a sample of where this appears in the file. Could you show what is on line 33 of the file?

hopperelec avatar Dec 30 '23 11:12 hopperelec

As @HopperElec said, could you show where in the JSON are these characters? Are those message fields? We can filter them out if the Telegram exporter is generating invalid JSONs (I guess they are not being escaped correctly)

mlomb avatar Jan 06 '24 19:01 mlomb

The best way is to escape ALL using script above, cause this characters may appear in unexpected places of exported json

thesingodim avatar Feb 05 '24 11:02 thesingodim

Can you test if your JSON is read by any other known tool (JS's JSON.parse, or any JSON visualizer tool)? We are using a custom implementation and may be bugged. For example, we are using charCodeAt(i) > 0 which I think is wrong, and may be causing problems with your 0x00 characters.

mlomb avatar Feb 19 '24 19:02 mlomb