Serialize keys using JSON.serialize

uri.format() is a bad choice for serialization when non-standard
properties are tacked on (and when .query properties aren't also
included in path)