We then convert it to json using RequestSchema.dump()
before sending it as the body in a http post request.
I am rewriting this code in elixir and I stumbled upon this erlang library called orddict
that I can use to convert my payload to an ordered dict in elixir.
My challenge is in the final step of converting the output of orddict to json using Jason.encode
As soon as you convert anything to JSON the order of the keys in an object is not guaranteed. Therefore I’m not sure your objective can be achieved if JSON is the intermediate representation.
An object is an unordered collection of zero or more name/value
pairs, where a name is a string and a value is a string, number,
boolean, null, object, or array
So even if Jason supports it, there isn’t a guarantee the corresponding party would conform to that?
Yeah. Afaik the biggest reason for handling json objects in an ordered fashion is preventing unnecessary differences between input and output when decoding and encoding from and to json is involved. Order shouldn‘t affect the represented data, but it will affect the representation itself.
I gave this argument to the API owners and they
said that it is no longer a requirement to have the params ordered
and that it was a case of outdated documentation.