DaveGamble / cJSON

Ultralightweight JSON parser in ANSI C
MIT License
10.72k stars 3.21k forks source link

Question about "standards" #192

Closed ErosOlmi closed 7 years ago

ErosOlmi commented 7 years ago

I have a question about "standards"

I got crazy about a server that returns, for the same node, an array or an object depending on how many items are present. If only one item is present, it returns an object. If more items are present, it returns an array. My question is: is it correct behave?

My idea is that even if 1 item or zero items are present, it should return an array. But maybe I'm wrong

Below examples for the 2 conditions. Node changing type is "Movimento". First example is with one element, second example is with 3 elements.

Thanks in advance Eros


{
  "status" : {
    "code" : "OK",
    "description" : "Transaction List retrieved successfully"
  },
  "error" : {
    "description": ""
  },
  "payload": [
    {
  "ListaMovimenti" : {
    "Movimento" : {
      "DataContabile" : "27/07/2017",
      "Importo" : "100,00",
      "Segno" : "A",
      "Divisa" : "EUR",
      "DataValuta" : "27/07/2017",
      "Terminale" : "yyyyyy",
      "CausaleVariabile" : "BD xxxxxxxxxxxxxxxxxxxxxxx",
      "Controvalore" : "100,00",
      "NumeroOperazioneH2O" : "19870987098789",
      "NumeroProgressivoHost" : "765786576",
      "IdMovimentoH2O" : "9879879087"
    }
  }
}
  ]
}

{
  "status" : {
    "code" : "OK",
    "description" : "Transaction List retrieved successfully"
  },
  "error" : {
    "description": ""
  },
  "payload": [
    {
  "ListaMovimenti" : {
    "Movimento" : [ {
      "DataContabile" : "28/07/2017",
      "Importo" : "293,57",
      "Segno" : "A",
      "Divisa" : "EUR",
      "DataValuta" : "28/07/2017",
      "Terminale" : "983",
      "CausaleVariabile" : "IA ttttttttt58468 2707",
      "Controvalore" : "293,57",
      "NumeroOperazioneH2O" : "3452345",
      "NumeroProgressivoHost" : "34523",
      "IdMovimentoH2O" : "34523"
    }, {
      "DataContabile" : "28/07/2017",
      "Importo" : "200,37",
      "Segno" : "A",
      "Divisa" : "EUR",
      "DataValuta" : "28/07/2017",
      "Terminale" : "983",
      "CausaleVariabile" : "IA POS3077vvvvvvvv84-27/07",
      "Controvalore" : "200,37",
      "NumeroOperazioneH2O" : "3534523",
      "NumeroProgressivoHost" : "345234",
      "IdMovimentoH2O" : "3523"
    }, {
      "DataContabile" : "27/07/2017",
      "Importo" : "100,00",
      "Segno" : "A",
      "Divisa" : "EUR",
      "DataValuta" : "27/07/2017",
      "Terminale" : "yyyyyy",
      "CausaleVariabile" : "uyiuyiuyiuyiuyiuyiu    ",
      "Controvalore" : "100,00",
      "NumeroOperazioneH2O" : "34523435235",
      "NumeroProgressivoHost" : "35235",
      "IdMovimentoH2O" : "3523452354"
    } ]
  }
}
  ]
}
FSMaxB commented 7 years ago

The JSON standards are only describing the data format itself, not how to use them.

There are certainly standards out there about how data should be represented in JSON form, but I don't think there is any definitive standard on it. Also I'm not familiar enough with it to name any one standard.

All I can give you is my personal opinion: If something is a collection, it should stay a collection no matter how many entries. So in case of 0 elements it should be an empty array, one or more elements should be an array with entries. Anything else is just inconsistent and making it harder both for implementing the server and the client.

But just my opinion as I said.

ErosOlmi commented 7 years ago

Thanks a lot. Your opinion is also my opinion. I will complain with who has created this export :)