If you export a DataSet, you get an object where each member is a table based on the table name. The table itself is an object with two members, namely “columns” and “rows”. The “columns” member is an array of column names whereas “rows” is an array of rows where each row is an array of values. The shape looks like this:
{
"Employees" : {
"columns" : [
"EmployeeID", "LastName", "FirstName" ],
"rows" : [
[ "1", "Davolio", "Nancy" ],
[ "2", "Fuller", "Andrew" ],
[ "3", "Leverling", "Janet" ]
}
}
When you export a DataTable, you get just the object with columns and rows:
{
"columns" : [
"EmployeeID", "LastName", "FirstName" ],
"rows" : [
[ "1", "Davolio", "Nancy" ],
[ "2", "Fuller", "Andrew" ],
[ "3", "Leverling", "Janet" ]
}
In both these cases, you can turn a table into a more accessible object on the client end. For example, when you receive the JSON representation of a DataSet on the client in JavaScript, you can convert the table rows into first-class objects by adding a handy method to the base Array object:
Array.prototype.toObject = function(names)
{
var o = {} ;
for (var i = 0; i < names.length; i++)
o[names[i]] = i < this.length ? this[i] : null;
return o;
}
Given this, you can convert a row that is an array of values into an object by supplying the column names as the first parameter:
var table = ds[0]; // get the first table in the dataset
var row = table.rows[0].toObject(table.columns);
Now you can do row["FirstName"].
Finally, if you export a DataRowCollection or just an array of DataRows, then they’re formatted out directly as JSON objects:
[
{
"EmployeeID" : "1",
"LastName" : "Davolio",
"FirstName" : "Nancy",
},
{
"EmployeeID" : "2",
"LastName" : "Fuller",
"FirstName" : "Andrew"
},
{
"EmployeeID" : "3",
"LastName" : "Leverling",
"FirstName" : "Janet"
}
]
HTH