I have a JSON file that was converted from a csv and is too big to hand edit. Its’ syntax is one large array I think. The data is from a group of routers and I aim to build router objects. The way the current CSV to JSON file is organized by each row and I want to pick out each router and have an object with router name, the all bandwidth measurements associated with that router.
How would you approach this? I’m attempting to take care of all of this when I iterate through the JSON file and when the router changes, I start a new instance of the router object. I’m a no longer a newb, just a slow learner. So would the next step be to create a router class with js and populate the class with what I pull out of my giant JSON array, or could/should I do with out the handwritten class and create all the objects on the fly? (can I create objects on the fly.
Current JSON (it goes on for pages, each router having a few hundred entries in the csv:
[
{
"Router": "RouterID1",
"TimeStamp": "2012/01/01 06:00:00",
"transferBytes": "23235",
"ReceivedBytes": "29903"
},
{
"Router": "RouterID1",
"TimeStamp": "2012/01/01 06:05:00",
"transferBytes": "21235",
"ReceivedBytes": "22103"
}
{
"Router": "RouterID2",
"TimeStamp": "2012/01/01 06:00:00",
"transferBytes": "23235",
"ReceivedBytes": "29903"
},
{
"Router": "RouterID2",
"TimeStamp": "2012/01/01 06:05:00",
"transferBytes": "21235",
"ReceivedBytes": "22103"
}
]
@amnotiam: the router types are gauranteed to be adjecent to each other
This might not be valid but here is the structure I think I’m going for:
[
{
"Router": "RouterID1"
"TimeStamp": array of timestamps
"transferBytes": array of bytes transferred for each timestamp
"ReceivedBytes": array of bytes received for each timestamp
},
{
"Router": "RouterID2",
"TimeStamp": array of timestamps
"transferBytes": array of bytes transferred for each timestamp
"ReceivedBytes": array of bytes received for each timestamp
}
]
@Bergi I want to make an object for each router with there historical data contained with in the object. Right know I have an object for every time entry. (I think)
@Rick Good call, I will be and will probably ask that question later:)
You can really just create the objects on the fly. It’s not going to be any faster to hardcode a set of router objects, and it’s likely you’ll make mistakes by handwriting.
Take a look at this : http://jsfiddle.net/aSbm6/