JSON feed from third party

JSON feed from third party

neburtonneburton Posts: 63Questions: 6Answers: 0
edited February 2014 in General
Hi Allan,

I receive a JSON feed of phone call logs from our telephony provider.

The feed is in name/value pairs and looks like this :

[code]

[{"id":9429993,"i_account":1985,"i_customer":654,"CallRecordingAvailable":true,"MP3RecordingAvailable":true,"Withheld":false,"Transfered":false,"CLD":"441534750520","CLI":"441452841172","Note":"","AccountID":"441452841172","call_id":"22e287138510393165980k61855rmwp","SessionID":null,"Direction":"outbound","LastCallStatus":"","CallRecordingURL":"https://api.synety.com/accounts/441452841172/calls/9429993/recordingurl?auth=f0833e607efe693b69e040ce12aac467&expiryDate=2014-03-22T16:25:20","CallRecordingHash":"f0833e607efe693b69e040ce12aac467","ConnectTime":"2013-09-16T12:20:15","DisconnectTime":"2013-09-16T12:20:34","LastUpdated":"2013-09-16T12:20:58Z","ExpiryTime":"2014-03-22T16:25:20.4147735+00:00","TransferTime":null,"ChargedAmount":0.01000,"ChargedTime":0,"CategoryID":null,"ContactID":null,"Category":null,"Contact":null,"CallStatus":null,"ForwardedCalls":null},{"id":8985051,"i_account":1985,"i_customer":654,"CallRecordingAvailable":true,"MP3RecordingAvailable":true,"Withheld":false,"Transfered":false,"CLD":"441534750520","CLI":"441452841172","Note":"","AccountID":"441452841172","call_id":"34e8901526185916939323k65950rmwp","SessionID":null,"Direction":"outbound","LastCallStatus":"","CallRecordingURL":"https://api.synety.com/accounts/441452841172/calls/8985051/recordingurl?auth=221c43cba757a5599d721baa6b56c9e6&expiryDate=2014-03-22T16:25:20","CallRecordingHash":"221c43cba757a5599d721baa6b56c9e6","ConnectTime":"2013-09-06T13:38:29","DisconnectTime":"2013-09-06T13:38:47","LastUpdated":"2013-09-06T13:39:30Z","ExpiryTime":"2014-03-22T16:25:20.4147735+00:00","TransferTime":null,"ChargedAmount":0.01000,"ChargedTime":0,"CategoryID":null,"ContactID":null,"Category":null,"Contact":null,"CallStatus":null,"ForwardedCalls":null}]

[/code]

Previously my code has searched and replaced the name part of the name value pairs to produce a value array that datatables understands. However the provider keeps changing the order of the fields in the feed and when I complain, tells me "JSON is an unordered set of name value pairs", to which I responded "It doesn't have to be!".

Anyway, any idea how I can cope with the random field positions?

Replies

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    @neburton: I must be missing something - if you've already been searching the name/value pairs before handing off to DataTables, surely the order doesn't matter? Just build a de-jsoned array in the order you need, then re-json it? But I'm probably missing something.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I suspect what is happening is that you are converted to an array format - is that correct? If so, don't bother with that. Since DataTables 1.8 it has been able to read just about any data source through the use of the mData option (previously called mDataProp and now simply `data` in 1.10 - all backwards compatible!).

    This blog post has more information for 1.9-: http://datatables.net/blog/Extended_data_source_options_with_DataTables

    And for 1.10+: http://next.datatables.net/manual/data#Objects

    That way, no conversion is needed - just always use the raw JSON data source.

    Allan
This discussion has been closed.