jb31
jb31

Reputation: 19

Splitting JSON data into two separate arrays

I'm trying to take a JSON url and process all of the information into two separate arrays. The first array on the data begins with "output_no_match", and the second array is identically formatted and begins with "avalanche_with_match". I'm stuck on how exactly to get the data into two separate arrays to then process (and put into a graph).

Thanks for any help!

[{"date":"2014-12-01T00:00:00-06:00"
"id":null
"balance":915047.12
"interest":710669475.15
"interest_paid":10199.29
"ending_principal_balance":915047.12
"ending_interest_balance":710659275.86
"payment_due":10199.29}

Upvotes: 1

Views: 103

Answers (1)

Michael L.
Michael L.

Reputation: 369

suppose you have a file located at http://your-host.com/sampleData.json containing your JSON data :

{"output_no_match": [{
    "date": "2014-12-01T00:00:00-06:00",
    "id": null,
    "balance": 915047.12,
    "interest": 710669475.15,
    "interest_paid": 10199.29,
    "ending_principal_balance": 915047.12,
    "ending_interest_balance": 710659275.86,
    "payment_due": 10199.29
}],
"avalanche_with_match": [{
    "date": "2014-12-01T00:00:00-06:00",
    "id": null,
    "balance": 915047.12,
    "interest": 710669475.15,
    "interest_paid": 10199.29,
    "ending_principal_balance": 915047.12,
    "ending_interest_balance": 710659275.86,
    "payment_due": 10199.29
}]},

then you can get it with XMLHttpRequest (using jQuery):

$.get('http://your-host/sampleData.json').success(function(data){
   //data is js object with your arrays
});

Upvotes: 1

Related Questions