0
votes

i'm a beginner with python and i need some help in order to read a json file which has some tweets as data.

I have saved these data on a json file and when i try to read the file. I got some errors:

ValueError: Expecting value: line 2 column 1 (char 1)

Can someone help me please?

My json file content is: {"created_at":"Mon Aug 07 08:38:17 +0000 2017","id":894477786047553536,"id_str":"894477786047553536","text":"@KevinRobMartin @PSTeamOnline @PokerStars Modern 5-7-9 card poker. The Holadeck: \nAHD rule: All Hands on Deck - all\u2026 https://t.co/gOzpJgwcgX","display_text_range":[42,140],"source":"\u003ca href=\"http://twitter.com\" rel=\"nofollow\"\u003eTwitter Web Client\u003c/a\u003e","truncated":true,"in_reply_to_status_id":894310275763113985,"in_reply_to_status_id_str":"894310275763113985","in_reply_to_user_id":2483027940,"in_reply_to_user_id_str":"2483027940","in_reply_to_screen_name":"KevinRobMartin","user":{"id":812269114551136256,"id_str":"812269114551136256","name":"Chesmayne","screen_name":"Chesmayne2017","location":"Dublin Ireland Europe Gaia ","url":"http://homepage.eircom.net/~reidr1/index.html","description":"Leanne Jordan. Game Web Graphic Print Designer CEO & Social Media: CHESS, POKER, Astronomy. Contact me by G-mail: [email protected]","protected":false,"verified":false,"followers_count":251,"friends_count":423,"listed_count":9,"favourites_count":1030,"statuses_count":3597,"created_at":"Fri Dec 23 12:10:22 +0000 2016","utc_offset":null,"time_zone":null,"geo_enabled":true,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http://abs.twimg.com/images/themes/theme1/bg.png","profile_background_image_url_https":"https://abs.twimg.com/images/themes/theme1/bg.png","profile_background_tile":false,"profile_link_color":"981CEB","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"000000","profile_text_color":"000000","profile_use_background_image":false,"profile_image_url":"http://pbs.twimg.com/profile_images/873654899220860929/Gh1zCGk4_normal.jpg","profile_image_url_https":"https://pbs.twimg.com/profile_images/873654899220860929/Gh1zCGk4_normal.jpg","profile_banner_url":"https://pbs.twimg.com/profile_banners/812269114551136256/1497130468","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":{"id":"7dde0febc9ef245b","url":"https://api.twitter.com/1.1/geo/id/7dde0febc9ef245b.json","place_type":"city","name":"Dublin City","full_name":"Dublin City, Ireland","country_code":"IE","country":"Ireland","bounding_box":{"type":"Polygon","coordinates":[[[-6.387438,53.298745],[-6.387438,53.411060],[-6.107805,53.411060],[-6.107805,53.298745]]]},"attributes":{}},"contributors":null,"is_quote_status":false,"extended_tweet":{"full_text":"@KevinRobMartin @PSTeamOnline @PokerStars Modern 5-7-9 card poker. The Holadeck: \nAHD rule: All Hands on Deck - all hands allowed\nLatest: https://t.co/FDxM8RoITY https://t.co/Rx0Kiu3FRN","display_text_range":[42,161],"entities":{"hashtags":[],"urls":[{"url":"https://t.co/FDxM8RoITY","expanded_url":"https://www.facebook.com/ches.mayne.9","display_url":"facebook.com/ches.mayne.9","indices":[138,161]}],"user_mentions":[{"screen_name":"KevinRobMartin","name":"Kevin Martin","id":2483027940,"id_str":"2483027940","indices":[0,15]},{"screen_name":"PSTeamOnline","name":"Team Pro Online","id":245412615,"id_str":"245412615","indices":[16,29]},{"screen_name":"PokerStars","name":"PokerStars","id":19537263,"id_str":"19537263","indices":[30,41]}],"symbols":[],"media":[{"id":894477755517218818,"id_str":"894477755517218818","indices":[162,185],"media_url":"http://pbs.twimg.com/media/DGnSx40XsAIUwF_.jpg","media_url_https":"https://pbs.twimg.com/media/DGnSx40XsAIUwF_.jpg","url":"https://t.co/Rx0Kiu3FRN","display_url":"pic.twitter.com/Rx0Kiu3FRN","expanded_url":"https://twitter.com/Chesmayne2017/status/894477786047553536/photo/1","type":"photo","sizes":{"medium":{"w":960,"h":640,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"},"large":{"w":960,"h":640,"resize":"fit"},"small":{"w":680,"h":453,"resize":"fit"}}},{"id":894477778439024643,"id_str":"894477778439024643","indices":[162,185],"media_url":"http://pbs.twimg.com/media/DGnSzONWsAMaj2_.jpg","media_url_https":"https://pbs.twimg.com/media/DGnSzONWsAMaj2_.jpg","url":"https://t.co/Rx0Kiu3FRN","display_url":"pic.twitter.com/Rx0Kiu3FRN","expanded_url":"https://twitter.com/Chesmayne2017/status/894477786047553536/photo/1","type":"photo","sizes":{"medium":{"w":960,"h":640,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"},"large":{"w":960,"h":640,"resize":"fit"},"small":{"w":680,"h":453,"resize":"fit"}}}]},"extended_entities":{"media":[{"id":894477755517218818,"id_str":"894477755517218818","indices":[162,185],"media_url":"http://pbs.twimg.com/media/DGnSx40XsAIUwF_.jpg","media_url_https":"https://pbs.twimg.com/media/DGnSx40XsAIUwF_.jpg","url":"https://t.co/Rx0Kiu3FRN","display_url":"pic.twitter.com/Rx0Kiu3FRN","expanded_url":"https://twitter.com/Chesmayne2017/status/894477786047553536/photo/1","type":"photo","sizes":{"medium":{"w":960,"h":640,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"},"large":{"w":960,"h":640,"resize":"fit"},"small":{"w":680,"h":453,"resize":"fit"}}},{"id":894477778439024643,"id_str":"894477778439024643","indices":[162,185],"media_url":"http://pbs.twimg.com/media/DGnSzONWsAMaj2_.jpg","media_url_https":"https://pbs.twimg.com/media/DGnSzONWsAMaj2_.jpg","url":"https://t.co/Rx0Kiu3FRN","display_url":"pic.twitter.com/Rx0Kiu3FRN","expanded_url":"https://twitter.com/Chesmayne2017/status/894477786047553536/photo/1","type":"photo","sizes":{"medium":{"w":960,"h":640,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"},"large":{"w":960,"h":640,"resize":"fit"},"small":{"w":680,"h":453,"resize":"fit"}}}]}},"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[{"url":"https://t.co/gOzpJgwcgX","expanded_url":"https://twitter.com/i/web/status/894477786047553536","display_url":"twitter.com/i/web/status/8\u2026","indices":[117,140]}],"user_mentions":[{"screen_name":"KevinRobMartin","name":"Kevin Martin","id":2483027940,"id_str":"2483027940","indices":[0,15]},{"screen_name":"PSTeamOnline","name":"Team Pro Online","id":245412615,"id_str":"245412615","indices":[16,29]},{"screen_name":"PokerStars","name":"PokerStars","id":19537263,"id_str":"19537263","indices":[30,41]}],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en","timestamp_ms":"1502095097444"}

filename = 'publictweets.json' 
with open(filename, 'r') as f: 
    count_all = Counter() 
    for line in f: 
        tweet = json.loads(line)
1
Please share the code that you have tried till nowUser_Targaryen
You need to add the code and example of your file content to your questionettanany
filename = 'publictweets.json' with open(filename, 'r') as f: count_all = Counter() for line in f: tweet = json.loads(line)Student
Use all_tweets = json.load(f)stovfl
I have already done this way but it does not work. I give me this error: ValueError: Extra data: line 3 column 1 - line 3869 column 1 (char 6475 - 708232)Student

1 Answers

0
votes

I have been able to solve out the problem and thanks for your helps.

   filename = 'publictweets.json'
   with open(filename, 'r') as f:
        for line in f:
            if line.strip():
               tweet = json.loads(line)