Just why are some JSON requests in [] and others not?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JayBee
    Junior Member
    • Oct 2010
    • 114

    #1

    Just why are some JSON requests in [] and others not?

    That is a question that has always been at the back of my mind.

    For example...

    [{"jsonrpc":"2.0","method":"SportsAPING/v1.0/listMarketCatalogue","params":{"filter":{"eventTyp eIds":["7"],"marketCountries":["GB","IRL"],"marketTypeCodes":["WIN"]},"maxResults":"200","marketProjection":["MARKET_START_TIME","RUNNER_DESCRIPTION","EVEN T"]},"id":1}]

    What is the point of a list of 1 item, the JSON string?

    It just adds an extra layer of noodling.

    And why bother with jsonrpc and id in the response? If Betfair wants less data transfer and we want quicker processing of data then why the extra guff on the response?
  • AlgoTrader
    Junior Member
    • Mar 2012
    • 243

    #2
    Single value is String: "STUFF"

    Square brackets is Array: ["STUFF_1", "STUFF_2"]

    Sometimes arrays have just a single value, then it looks like ["STUFF"]. But it is still array!
    Betfair Bots Made Easy

    Comment

    • JayBee
      Junior Member
      • Oct 2010
      • 114

      #3
      Originally posted by AlgoTrader View Post
      Single value is String: "STUFF"

      Square brackets is Array: ["STUFF_1", "STUFF_2"]

      Sometimes arrays have just a single value, then it looks like ["STUFF"]. But it is still array!
      Remove the brackets from both ends of the string and you have a nice clean object.

      Take the getAccountFunds method...

      [{"jsonrpc":"2.0","result":{"availableToBetBalance" :874.52,"exposure":0.0,"retainedCommission":0.0,"e xposureLimit":-5000.0},"id":1}]

      Remove the square brackets at the beginning and the end and you don't lose anything. In fact you have an object. With brackets you have an array of objects but still only the one object. It seems rather pointless to be traversing an array with only 1 element in it.

      In creating a JSON request I have to create a list when just an object without square brackets would make more sense seeing as you are only sending the one object.

      I like things to be clean and tidy. I see no reason for the string to encased in square brackets. I use a lot of JSON APIs and Betfair's is the only one that does this.

      Comment

      • bnl
        Junior Member
        • Nov 2012
        • 108

        #4
        Originally posted by JayBee View Post
        Remove the brackets from both ends of the string and you have a nice clean object.
        You loose the ability to treat all responses of that kind
        in the same way, looping over the array.

        Suddenly, you can't trust the description of
        the service anymore. You have to manually check for
        existence of arrays. Perhaps you'd like to get rid of
        "" for strings as well ?

        Even if typeless is the new black, some
        people like to know what is supposed to come back as reply,
        instead of guessing. I am definitively one of them.

        /Björn

        Comment

        • Fred77
          Junior Member
          • Jan 2009
          • 37

          #5
          As per the JSON-RPC 2.0 Specification "Batch" - If you send an array of request objects you'll receive an array of response objects.

          You are getting an array of one object as a response because your request is an array of one object.

          Remove the outer [ ] from your request if you want them removed from the response.

          Calls to login, logout, keepalive are to a different system which isn't JSON-RPC 2.0, neither the request nor response has [].

          Comment

          Working...
          X