Test for string instead of float in encode

Only call the replace method on variables that would have it (strings). Otherwise booleans (true, false) throw an error during encoding.