cppp-io icon indicating copy to clipboard operation
cppp-io copied to clipboard

Params ordering

Open kevin-brown opened this issue 8 years ago • 1 comments

Right now the section "Params" states

When parsing params submitted by a client, the server should examine the request body, looking for JSON-formatted params. If params are present in the request body, they should be used.

Params order should be determined by their order in the request.

Which goes against the JSON specification and forces that the JSON request is ordered, and that whatever JSON parser is used maintains the order [1].

From JSON.org

An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma).

There are a few possible solutions, each with their own problems

  • Use a JSON array, which is ordered
  • Order the JSON object based on the keys (sort the keys, then retrieve the values based on that sort)
  • Attempt to use the keys as named parameters (in languages that support it)

[1]: Even _.values may not be ordered, which is what Cylon uses.

kevin-brown avatar Jul 26 '15 00:07 kevin-brown

Hello! We currently use a JSON object represent params to, as you mention in your issue, support languages with named parameters. We had difficulty finding a solution that worked across many different languages, and decided to use this despite the risk of re-ordering, as we've yet to really see this happen in practice. We acknowledge that this is likely a boneheaded move on our (mostly my) part.

Although, thinking on it now, perhaps a better solution would be an array of arrays? I seem to remember this coming up but being dismissed, and I'm unsure why.

{
  "params": [
    ["a", "alpha"],
    ["b", "bravo"],
  ]
}

@deadprogram + @zankich, thoughts?

stewart avatar Jul 27 '15 15:07 stewart