code: def json2datetime(json):
          
          
          json_m = re.search(r'([0-9]+,[0-9]+,[0-9]+)(,[0-9]+,[0-9]+,[0-9]+)?(,[0-9]+)?', json)
          args=json_m.group(0).split(',')
          
          try:
              args=map(int, args)
          except ValueError:
              raise ValueError('Invalid arguments: %s'%json)
  
          if len(args)==3: 
              return datetime.datetime(args[0], args[1]+1, args[2])
          elif len(args)==6: 
              return datetime.datetime(args[0], args[1]+1, args[2], 
                                      args[3], args[4], args[5], tzinfo=UTC())
          elif len(args)==7:
              args[6]*=1000
              return datetime.datetime(args[0], args[1]+1, args[2], 
                                      args[3], args[4], args[5], args[6], tzinfo=UTC())
          raise ValueError('Invalid number of arguments: %s'%json)
docs: Convert JSON representation to date or datetime object depending on
          the argument count. Requires UTC datetime representation.
          Raises ValueError if the string cannot be parsed.