fork download
  1. from json import JSONDecoder, JSONDecodeError
  2. import re, sys
  3.  
  4. NOT_WHITESPACE = re.compile(r'[^\s]')
  5.  
  6. def decode_stacked(document, pos=0, decoder=JSONDecoder()):
  7. while True:
  8. match = NOT_WHITESPACE.search(document, pos)
  9. if not match:
  10. return
  11. pos = match.start()
  12.  
  13. try:
  14. obj, pos = decoder.raw_decode(document, pos)
  15. except JSONDecodeError:
  16. # do something sensible if there's some error
  17. raise
  18. yield obj
  19.  
  20. for object in decode_stacked(sys.stdin.read()):
  21. sys.stdout.write("Decoded: %r\n" % object)
Success #stdin #stdout 0.02s 30184KB
stdin
{"id":"tag:search.twitter.com,2005:143726332","objectType":"activity","actor":{"objectType":"person","id":"id:twitter.com:2477461","link":"http://w...content-available-to-author-only...r.com/lastmac","displayName":"Last Mac News [IT] ","postedTime":"2007-01-27T12:16:12.000Z","image":"italiagl1.png","summary":"Le ultime news italiane sul mondo Mac","links":[{"href":"http://w...content-available-to-author-only...c.com","rel":"me"}],"friendsCount":0,"followersCount":0,"listedCount":0,"statusesCount":0,"twitterTimeZone":"Rome","verified":false,"utcOffset":"0","preferredUsername":"lastmac","languages":[""],"location":{"objectType":"place","displayName":"Italia"},"favoritesCount":0},"verb":"post","postedTime":"2007-07-10T23:00:35.000Z","generator":{"displayName":"twitterfeed","link":"http://t...content-available-to-author-only...r.com"},"provider":{"objectType":"service","displayName":"Twitter","link":"http://w...content-available-to-author-only...r.com"},"link":"http://t...content-available-to-author-only...r.com/lastmac/statuses/143726332","body":"JP Morgan retracts report: No to iPhone Nano: JP Morgan has just issued a note retracting Kevin Chang's e.. http://t...content-available-to-author-only...l.com/yrgat7","object":{"objectType":"note","id":"object:search.twitter.com,2005:143726332","summary":"JP Morgan retracts report: No to iPhone Nano: JP Morgan has just issued a note retracting Kevin Chang's e.. http://t...content-available-to-author-only...l.com/yrgat7","link":"http://t...content-available-to-author-only...r.com/lastmac/statuses/143726332","postedTime":"2007-07-10T23:00:35.000Z"},"twitter_entities":{"urls":[{"expanded_url":null,"indices":[108,133],"url":"http://t...content-available-to-author-only...l.com/yrgat7"}],"hashtags":[],"user_mentions":[]},"retweetCount":0,"gnip":{"matching_rules":[{"value":"\"JP Morgan\"","tag":null}]}}
{"id":"tag:search.twitter.com,2005:143731422","objectType":"activity","actor":{"objectType":"person","id":"id:twitter.com:3491001","link":"http://w...content-available-to-author-only...r.com/diggfeed","displayName":"digg feed","postedTime":"2007-01-05T04:38:37.000Z","image":"digg.jpg","summary":"","links":[{"href":"","rel":"me"}],"friendsCount":0,"followersCount":0,"listedCount":0,"statusesCount":0,"twitterTimeZone":"Pacific Time (US & Canada)","verified":false,"utcOffset":"0","preferredUsername":"diggfeed","languages":[""],"favoritesCount":0},"verb":"post","postedTime":"2007-07-10T23:04:37.000Z","generator":{"displayName":"twitterfeed","link":"http://t...content-available-to-author-only...r.com"},"provider":{"objectType":"service","displayName":"Twitter","link":"http://w...content-available-to-author-only...r.com"},"link":"http://t...content-available-to-author-only...r.com/diggfeed/statuses/143731422","body":"JP Morgan retracts report: No to iPhone Nano: JP Morgan has just issued a note retracting Kevin Chang's .. http://t...content-available-to-author-only...l.com/yuo7uu","object":{"objectType":"note","id":"object:search.twitter.com,2005:143731422","summary":"JP Morgan retracts report: No to iPhone Nano: JP Morgan has just issued a note retracting Kevin Chang's .. http://t...content-available-to-author-only...l.com/yuo7uu","link":"http://t...content-available-to-author-only...r.com/diggfeed/statuses/143731422","postedTime":"2007-07-10T23:04:37.000Z"},"twitter_entities":{"urls":[{"expanded_url":null,"indices":[107,132],"url":"http://t...content-available-to-author-only...l.com/yuo7uu"}],"hashtags":[],"user_mentions":[]},"retweetCount":0,"gnip":{"matching_rules":[{"value":"\"JP Morgan\"","tag":null}]}}
{"info":{"message":"Replay Request Completed","sent":"2014-05-31T12:45:25+00:00","activity_count":2}}
stdout
Decoded: {'id': 'tag:search.twitter.com,2005:143726332', 'retweetCount': 0, 'object': {'summary': "JP Morgan retracts report: No to iPhone Nano: JP Morgan has just issued a note retracting Kevin Chang's e.. http://t...content-available-to-author-only...l.com/yrgat7", 'id': 'object:search.twitter.com,2005:143726332', 'link': 'http://t...content-available-to-author-only...r.com/lastmac/statuses/143726332', 'objectType': 'note', 'postedTime': '2007-07-10T23:00:35.000Z'}, 'body': "JP Morgan retracts report: No to iPhone Nano: JP Morgan has just issued a note retracting Kevin Chang's e.. http://t...content-available-to-author-only...l.com/yrgat7", 'twitter_entities': {'hashtags': [], 'urls': [{'expanded_url': None, 'url': 'http://t...content-available-to-author-only...l.com/yrgat7', 'indices': [108, 133]}], 'user_mentions': []}, 'provider': {'link': 'http://w...content-available-to-author-only...r.com', 'objectType': 'service', 'displayName': 'Twitter'}, 'gnip': {'matching_rules': [{'value': '"JP Morgan"', 'tag': None}]}, 'link': 'http://t...content-available-to-author-only...r.com/lastmac/statuses/143726332', 'postedTime': '2007-07-10T23:00:35.000Z', 'actor': {'twitterTimeZone': 'Rome', 'id': 'id:twitter.com:2477461', 'location': {'objectType': 'place', 'displayName': 'Italia'}, 'links': [{'rel': 'me', 'href': 'http://w...content-available-to-author-only...c.com'}], 'friendsCount': 0, 'displayName': 'Last Mac News [IT] ', 'favoritesCount': 0, 'statusesCount': 0, 'listedCount': 0, 'preferredUsername': 'lastmac', 'link': 'http://w...content-available-to-author-only...r.com/lastmac', 'postedTime': '2007-01-27T12:16:12.000Z', 'utcOffset': '0', 'verified': False, 'summary': 'Le ultime news italiane sul mondo Mac', 'followersCount': 0, 'image': 'italiagl1.png', 'objectType': 'person', 'languages': ['']}, 'generator': {'link': 'http://t...content-available-to-author-only...r.com', 'displayName': 'twitterfeed'}, 'objectType': 'activity', 'verb': 'post'}
Decoded: {'id': 'tag:search.twitter.com,2005:143731422', 'retweetCount': 0, 'object': {'summary': "JP Morgan retracts report: No to iPhone Nano: JP Morgan has just issued a note retracting Kevin Chang's .. http://t...content-available-to-author-only...l.com/yuo7uu", 'id': 'object:search.twitter.com,2005:143731422', 'link': 'http://t...content-available-to-author-only...r.com/diggfeed/statuses/143731422', 'objectType': 'note', 'postedTime': '2007-07-10T23:04:37.000Z'}, 'body': "JP Morgan retracts report: No to iPhone Nano: JP Morgan has just issued a note retracting Kevin Chang's .. http://t...content-available-to-author-only...l.com/yuo7uu", 'twitter_entities': {'hashtags': [], 'urls': [{'expanded_url': None, 'url': 'http://t...content-available-to-author-only...l.com/yuo7uu', 'indices': [107, 132]}], 'user_mentions': []}, 'provider': {'link': 'http://w...content-available-to-author-only...r.com', 'objectType': 'service', 'displayName': 'Twitter'}, 'gnip': {'matching_rules': [{'value': '"JP Morgan"', 'tag': None}]}, 'link': 'http://t...content-available-to-author-only...r.com/diggfeed/statuses/143731422', 'postedTime': '2007-07-10T23:04:37.000Z', 'actor': {'twitterTimeZone': 'Pacific Time (US & Canada)', 'id': 'id:twitter.com:3491001', 'links': [{'rel': 'me', 'href': ''}], 'friendsCount': 0, 'displayName': 'digg feed', 'favoritesCount': 0, 'statusesCount': 0, 'listedCount': 0, 'preferredUsername': 'diggfeed', 'link': 'http://w...content-available-to-author-only...r.com/diggfeed', 'postedTime': '2007-01-05T04:38:37.000Z', 'utcOffset': '0', 'verified': False, 'summary': '', 'followersCount': 0, 'image': 'digg.jpg', 'objectType': 'person', 'languages': ['']}, 'generator': {'link': 'http://t...content-available-to-author-only...r.com', 'displayName': 'twitterfeed'}, 'objectType': 'activity', 'verb': 'post'}
Decoded: {'info': {'activity_count': 2, 'sent': '2014-05-31T12:45:25+00:00', 'message': 'Replay Request Completed'}}