Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

WHy is my JSON not importing into Python Pandas?

For some reason, my JSON is not importing into Python. I have tried using JSONlint but the error message I receive there seems to be conflicting with the one in Pandas.

Error: "Unexpected character found when decoding array value (2)"

The JSON I am using is a Telegram chat history that I have imported – so I’m a little confused as to why it won’t import. Below is a sample:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
 "name": "فاندامنتال | سرمایه گذاری مطمئن",
 "type": "public_channel",
 "id": 1151766431,
 "messages": [
  {
   "id": 1,
   "type": "service",
   "date": "2020-10-17T13:56:10",
   "actor": "فاندامنتال | سرمایه گذاری مطمئن",
   "actor_id": "channel1151766431",
   "action": "create_channel",
   "title": "استخراج رایگان بیت کوین | Free Bitcoin Mining",
   "text": ""
  },
  {
   "id": 3,
   "type": "message",
   "date": "2020-10-17T14:10:51",
   "edited": "2021-10-12T17:47:45",
   "from": "فاندامنتال | سرمایه گذاری مطمئن",
   "from_id": "channel1151766431",
   "author": "unconquerablee",
   "text": "سلام دوستان امیدوارم حال همگی خوب باشه اگه هم خوب نباشه با این کانال خوب‌ میشه😍\n\n📌لطفا مطالب این کانال رو با دقت و با حوصله دنبال کنین \n\n📌یه فرصت خیلی عالی هستش برای داشتن درآمد به صورت دلار\n\n 📌کاملا رایگان و بدون پرداخت حتی \n۱ ریال به هیچ شخص و هیچ نهادی \n\n📌در این اوضاع اقتصادی و ارزش ارز این روش بهترین راه برای کسب درآمد هستش\n\n📌📒این کانال در جهت مسائل بنیادی و فاندامنتال رمزارز ها فعالیت خواهد کرد.\n\n📍⁦🖋️⁩پس قدم به قدم با ما همراه باشین"
  },
  {
   "id": 4,
   "type": "message",
   "date": "2020-10-17T14:19:14",
   "edited": "2021-10-12T17:48:23",
   "from": "فاندامنتال | سرمایه گذاری مطمئن",
   "from_id": "channel1151766431",
   "author": "unconquerablee",
   "text": "صبور باشید تا دوستان بیشتری ملحق بشن تا باهم شروع کنیم.\n\nتعداد نفرات کانال : ۱۸نفر"
  },{
   "id": 9777,
   "type": "message",
   "date": "2021-08-19T10:13:09",
   "from": "فاندامنتال | سرمایه گذاری مطمئن",
   "from_id": "channel1151766431",
   "reply_to_message_id": 9732,
   "photo": "photos/photo_8124@19-08-2021_10-13-09.jpg",
   "width": 1080,
   "height": 837,
   "text": [
    {
     "type": "bold",
     "text": "🔊نسبت #پوزیشن‌ها در صرافی های مختلف در 24 ساعت گذشته‼️"
    },
    "\n\n📡بــا مــا هـمـراه بــاشید\nکانال فاندامنتال | سرمایه‌گذاری مطمئن"
   ]
  },
  {
   "id": 9778,
   "type": "message",
   "date": "2021-08-19T10:14:53",
   "edited": "2021-08-19T10:15:02",
   "from": "فاندامنتال | سرمایه گذاری مطمئن",
   "from_id": "channel1151766431",
   "reply_to_message_id": 9733,
   "photo": "photos/photo_8125@19-08-2021_10-14-53.jpg",
   "width": 1080,
   "height": 378,
   "text": [
    {
     "type": "bold",
     "text": "🔊 رمزارزهایی که در 24 ساعت گذشته بیشترین میزان لیکوئیدی را داشته اند‼️"
    },
    "\n\n🔸و در کل 74,026  نفر در ۲۴ ساعت گذشته لیکوئید شده‌اند.\n\n",
    {
     "type": "text_link",
     "text": "📡بــا مــا هـمـراه بــاشید\nکانال فاندامنتال | سرمایه‌گذاری مطمئن",
     "href": "http://t.me/fundamental2020"
    },
    ""
   ]
  },
  {
   "id": 9779,
   "type": "message",
   "date": "2021-08-19T10:15:43",
   "edited": "2021-08-19T10:15:51",
   "from": "فاندامنتال | سرمایه گذاری مطمئن",
   "from_id": "channel1151766431",
   "reply_to_message_id": 9734,
   "photo": "photos/photo_8126@19-08-2021_10-15-43.jpg",
   "width": 1080,
   "height": 467,
   "text": [
    {
     "type": "bold",
     "text": "🔊آمار لیکوئد شدن در صرافی‌ها در 24 ساعت گذشته‼️"
    },
    "\n\n🔸 بیش از 62 درصد پوزیشن‌های ",
    {
     "type": "hashtag",
     "text": "#Long"
    },
    " خرید ، لیکوئید شده‌اند\n\n",
    {
     "type": "text_link",
     "text": "📡بــا مــا هـمـراه بــاشید\nکانال فاندامنتال | سرمایه‌گذاری مطمئن",
     "href": "http://t.me/fundamental2020"
    },
    ""
   ]
  }

>Solution :

I can’t edit your question yet, but you seem to be missing a ] and } at the end of your json sample.

After adding that though, I could load the json as long as I used the extra keyword argument encoding='utf-8'. As you haven’t provided a code sample I cannot show you exactly where to add this keyword argument in your code, but here is the code I used to succesfully read the json:

import json

x = json.load(open('SO JSON question/input.json', encoding='utf-8'))
print(x)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading