1

I have a json file that I have to push into MongoDB. There are segments of data that are differently encoded. Like

{
    "Type":"File",
    "Start_Time":"2017-08-07T22:15:16.147Z",
    "Finish_Time":"2017-08-07T22:15:16.147Z",
    "Format":"UTF-16LE",
    "Message":"*' ¾Ò ,'H EÌ1Ò (F\/Ò ©Ì -A'8* ©1H ,( *ÌF ('1 ~‘¾*'¾Ò *H'DDG ~'© A14*   ",
    "Name_DB":"Main"}

And

{
    "Type":"File",
    "Start_Time":"2017-08-07T22:16:51.462Z",
    "Finish_Time":"2017-08-07T22:16:51.462Z",
    "Format":"ASCII",
    "Message":"SMS_CC_NR-InternType ISDN_NP +923330051108  From: UnkNumb Alphanumeric NR:EVC@ TID: 1123103757111462, Dear Retailer, U have successfully recharged 49 Rupee to 03325047863.Your current balance is 11257.00 Rupee.",
    "Name_DB":"Main"
        }

When I try to read the file, it throws a codec error. As you can see the two chunks have different formats - utf-16LE and ASCII.

How do I read this file?

shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
Shalini
  • 19
  • 4
  • 2
    This isn't the best way to store your data. – cs95 Aug 21 '17 at 13:01
  • There is one major problem here: you forgot to tell how the content of the *Message* field is encoded. Almost all characters are single bytes so they could be decoded as bytes, but there if a `‘` (U+2018 or LEFT SINGLE QUOTATION MARK) in it. And you failed to say what should be the decoded message. Without that important information you question is unanswerable, at least for me. – Serge Ballesta Aug 21 '17 at 14:13
  • I am not storing data this way. I am getting data in a json file which I have to push in MongoDB – Shalini Aug 21 '17 at 14:13
  • Could you show an hexa dump of the json file corresponding to the UTF16-LE encoded message, along with what should be the decoded form? – Serge Ballesta Aug 21 '17 at 14:15
  • The json files are pushed continuously. Hence, I have no idea what I will get as the message. – Shalini Aug 21 '17 at 15:23
  • If you ask to transform an input without saying what the output should be, the question is unanswerable. – Serge Ballesta Aug 21 '17 at 16:04

0 Answers0