Take the 2-minute tour ×
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It's 100% free, no registration required.

When I perform a ListAccounts query I get this:

  {
  "result": {
    "": 0.0,
    "account": 0.0,
    "account3": 0.0,
    "account7": 0.0
  },
  "error": null,
  "id": "1"
}

However ListReceivedByAccount(0, true); looks like this:

  {
   "result": [
     {
       "account": "",
       "amount": 0.0,
       "confirmations": 0
     },
     {
       "account": "account",
       "amount": 0.0,
       "confirmations": 0
     },
     {
       "account": "account3",
       "amount": 0.0,
       "confirmations": 0
     },
     {
       "account": "account7",
       "amount": 0.0,
       "confirmations": 0
     }
   ],
   "error": null,
   "id": "1"

Notice how the embedded array data is formatted differently? Is there a name or term that describes these different array formats (named vs unnamed)?

Why is it different and can this be fixed in a future version?

If it is fixed in a future version will the outermost "id" property become "2" so I can add the logic to my parsers?

share|improve this question
    
I initially voted to close this thinking it was off-topic (askng about JSON data types) but it is specific enough to bitcoin that I would withdraw that vote if I could. –  Stephen Gornick Dec 16 '12 at 22:34
    
@StephenGornick I made an edit so you can remove the downvote.. –  makerofthings7 Dec 16 '12 at 22:57

1 Answer 1

up vote 1 down vote accepted

JSON data structure supports lists (arrays).

In the first API command (ListAccounts) the result contents is an object which contains a string. Inside this string is a set of data records, each of which is a key/value item.

In the second (ListReceivedByAccount) the result contents is an array of objects, each of which holds account data.

That does appear inconsistent, where perhaps the first call should have returned an array as well.

However a rule of thumb is that existing APIs should not change. They can be deprecated and replaced but a call is expected to behave in a consistent manner.

The Bitcoin client is an open source project and thus an issue ticket for this inconsistency can be opened and a pull request with the source for a new API call submitted. Whether such an issue is merged into the client depends on a number of factors, including severity of problem.

share|improve this answer
    
Personally, I doubt a simple data structure inconsistency would get adopted, but if the ListAccounts API call ever does need revision it is likely the replacement call (again, under a different name) would incorporate the change so this inconsistency no longer exists. –  Stephen Gornick Dec 16 '12 at 22:31
    
Part of my question is, the outer most "id" element... is that some kind of versioning for the API.. all json results have that as "1". Perhaps a new version of the array or newly added types should return "2"? no? –  makerofthings7 Dec 16 '12 at 22:58
    
That id is the same one as your client sent. JSON-RPC answers just mirror the request id. –  Pieter Wuille Dec 17 '12 at 0:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.