Skip to content

Instantly share code, notes, and snippets.

@JensRantil
Created August 13, 2012 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JensRantil/3341985 to your computer and use it in GitHub Desktop.
Save JensRantil/3341985 to your computer and use it in GitHub Desktop.
Recreation of json.loads issue
"{\"coordinates\":null,\"in_reply_to_user_id\":159938854,\"truncated\":false,\"text\":\"@dstorna \\n\\u0627\\u062e\\u0648\\u064a \\u0639\\u0628\\u062f\\u0627\\u0644\\u0644\\u0647 \\u0627\\u0644\\u0631\\u0624\\u064a\\u0629 \\u062d\\u0642 \\u0648\\u0627\\u0644\\u062a\\u0641\\u0633\\u064a\\u0631 \\u0627\\u0644\\u0627\\u0648\\u0644 \\u0644\\u0647\\u0627 \\u064a\\u0642\\u0639 \\u0642\\u062f \\u064a\\u0636\\u062d\\u0643 \\u0627\\u062d\\u062f \\u0645\\u0639\\u0643 \\u0648\\u064a\\u0641\\u0633\\u0631\\u0647\\u0627 \\u0628\\u0633\\u0648\\u0621\",\"id_str\":\"234786337595727874\",\"entities\":{\"hashtags\":[],\"urls\":[],\"user_mentions\":[{\"indices\":[0,8],\"id_str\":\"159938854\",\"name\":\"\\u0639\\u0628\\u062f\\u0627\\u0644\\u0644\\u0647 \\u0627\\u0644\\u0634\\u0644\\u0627\\u062d\\u064a\",\"screen_name\":\"dstorna\",\"id\":159938854}]},\"place\":null,\"retweet_count\":0,\"favorited\":false,\"geo\":null,\"source\":\"\\u003Ca href=\\\"http:\\/\\/twitter.com\\/download\\/iphone\\\" rel=\\\"nofollow\\\"\\u003ETwitter for iPhone\\u003C\\/a\\u003E\",\"in_reply_to_status_id_str\":\"234779641922088960\",\"in_reply_to_screen_name\":\"dstorna\",\"in_reply_to_user_id_str\":\"159938854\",\"created_at\":\"Sun Aug 12 22:59:59 +0000 2012\",\"contributors\":null,\"user\":{\"profile_background_image_url_https\":\"https:\\/\\/si0.twimg.com\\/images\\/themes\\/theme14\\/bg.gif\",\"id_str\":\"324788637\",\"listed_count\":0,\"lang\":\"en\",\"profile_use_background_image\":true,\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1700186533\\/image_normal.jpg\",\"location\":\"\\u0627\\u0644\\u0643\\u0648\\u064a\\u062a\",\"follow_request_sent\":null,\"profile_text_color\":\"333333\",\"default_profile\":false,\"profile_background_image_url\":\"http:\\/\\/a0.twimg.com\\/images\\/themes\\/theme14\\/bg.gif\",\"description\":\"\\u0623\\u0634\\u0640\\u0640\\u0640\\u0648\\u0641 \\u0625\\u0646\\u0643 \\u0648\\u0637\\u0640\\u0646 \\u0644\\u0643\\u0646 ...\\u0648\\u0637\\u0640\\u0646 \\u064a\\u0633\\u062a\\u0627\\u0647\\u0644 \\u0627\\u0644\\u0647\\u062c\\u0640\\u0640\\u0631\\u0627\\u0646\",\"is_translator\":false,\"following\":null,\"profile_link_color\":\"009999\",\"followers_count\":1261,\"time_zone\":\"Kuwait\",\"profile_background_color\":\"131516\",\"default_profile_image\":false,\"contributors_enabled\":false,\"statuses_count\":10602,\"geo_enabled\":false,\"profile_background_tile\":true,\"protected\":false,\"favourites_count\":0,\"created_at\":\"Mon Jun 27 06:29:22 +0000 2011\",\"profile_sidebar_fill_color\":\"efefef\",\"name\":\"\\u0631\\u064a\\u0627\\u0636 \\u0627\\u0644\\u062e\\u0627\\u0644\\u062f\\u064a\",\"notifications\":null,\"url\":null,\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/1700186533\\/image_normal.jpg\",\"screen_name\":\"sa2002sa\",\"id\":324788637,\"show_all_inline_media\":true,\"verified\":false,\"utc_offset\":10800,\"friends_count\":538,\"profile_sidebar_border_color\":\"eeeeee\"},\"retweeted\":false,\"in_reply_to_status_id\":234779641922088960,\"id\":234786337595727874}\r"
from __future__ import print_function
import json
def test_parse(filename):
with open(filename) as f:
for tweet in f:
print("Line to import:", tweet)
data = json.loads(tweet)
print("The type of the imported data:", type(data))
test_parse('ddfs_xcat_-_less.txt')
@JensRantil
Copy link
Author

Output:

$ python test.py 
Line to import: "{\"coordinates\":null,\"in_reply_to_user_id\":159938854,\"truncated\":false,\"text\":\"@dstorna \\n\\u0627\\u062e\\u0648\\u064a \\u0639\\u0628\\u062f\\u0627\\u0644\\u0644\\u0647 \\u0627\\u0644\\u0631\\u0624\\u064a\\u0629 \\u062d\\u0642 \\u0648\\u0627\\u0644\\u062a\\u0641\\u0633\\u064a\\u0631 \\u0627\\u0644\\u0627\\u0648\\u0644 \\u0644\\u0647\\u0627 \\u064a\\u0642\\u0639 \\u0642\\u062f \\u064a\\u0636\\u062d\\u0643 \\u0627\\u062d\\u062f \\u0645\\u0639\\u0643 \\u0648\\u064a\\u0641\\u0633\\u0631\\u0647\\u0627 \\u0628\\u0633\\u0648\\u0621\",\"id_str\":\"234786337595727874\",\"entities\":{\"hashtags\":[],\"urls\":[],\"user_mentions\":[{\"indices\":[0,8],\"id_str\":\"159938854\",\"name\":\"\\u0639\\u0628\\u062f\\u0627\\u0644\\u0644\\u0647 \\u0627\\u0644\\u0634\\u0644\\u0627\\u062d\\u064a\",\"screen_name\":\"dstorna\",\"id\":159938854}]},\"place\":null,\"retweet_count\":0,\"favorited\":false,\"geo\":null,\"source\":\"\\u003Ca href=\\\"http:\\/\\/twitter.com\\/download\\/iphone\\\" rel=\\\"nofollow\\\"\\u003ETwitter for iPhone\\u003C\\/a\\u003E\",\"in_reply_to_status_id_str\":\"234779641922088960\",\"in_reply_to_screen_name\":\"dstorna\",\"in_reply_to_user_id_str\":\"159938854\",\"created_at\":\"Sun Aug 12 22:59:59 +0000 2012\",\"contributors\":null,\"user\":{\"profile_background_image_url_https\":\"https:\\/\\/si0.twimg.com\\/images\\/themes\\/theme14\\/bg.gif\",\"id_str\":\"324788637\",\"listed_count\":0,\"lang\":\"en\",\"profile_use_background_image\":true,\"profile_image_url_https\":\"https:\\/\\/si0.twimg.com\\/profile_images\\/1700186533\\/image_normal.jpg\",\"location\":\"\\u0627\\u0644\\u0643\\u0648\\u064a\\u062a\",\"follow_request_sent\":null,\"profile_text_color\":\"333333\",\"default_profile\":false,\"profile_background_image_url\":\"http:\\/\\/a0.twimg.com\\/images\\/themes\\/theme14\\/bg.gif\",\"description\":\"\\u0623\\u0634\\u0640\\u0640\\u0640\\u0648\\u0641 \\u0625\\u0646\\u0643 \\u0648\\u0637\\u0640\\u0646 \\u0644\\u0643\\u0646 ...\\u0648\\u0637\\u0640\\u0646 \\u064a\\u0633\\u062a\\u0627\\u0647\\u0644 \\u0627\\u0644\\u0647\\u062c\\u0640\\u0640\\u0631\\u0627\\u0646\",\"is_translator\":false,\"following\":null,\"profile_link_color\":\"009999\",\"followers_count\":1261,\"time_zone\":\"Kuwait\",\"profile_background_color\":\"131516\",\"default_profile_image\":false,\"contributors_enabled\":false,\"statuses_count\":10602,\"geo_enabled\":false,\"profile_background_tile\":true,\"protected\":false,\"favourites_count\":0,\"created_at\":\"Mon Jun 27 06:29:22 +0000 2011\",\"profile_sidebar_fill_color\":\"efefef\",\"name\":\"\\u0631\\u064a\\u0627\\u0636 \\u0627\\u0644\\u062e\\u0627\\u0644\\u062f\\u064a\",\"notifications\":null,\"url\":null,\"profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/1700186533\\/image_normal.jpg\",\"screen_name\":\"sa2002sa\",\"id\":324788637,\"show_all_inline_media\":true,\"verified\":false,\"utc_offset\":10800,\"friends_count\":538,\"profile_sidebar_border_color\":\"eeeeee\"},\"retweeted\":false,\"in_reply_to_status_id\":234779641922088960,\"id\":234786337595727874}\r"

The type of the imported data: <type 'unicode'>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment