Update base.rb

Added line "json = json.encode('utf-8', 'binary', :invalid => :replace, :undef => :replace)" to fix the folowin error "Error: lexical error: invalid bytes in UTF8 string."