I have a JSON array result from an API get in this form:

```
var data = {
"metadata": [{
    "colIndex": 0,
    "colType": "String",
    "colName": "Territory"
}, {
    "colIndex": 1,
    "colType": "String",
    "colName": "Region"
}, {
    "colIndex": 2,
    "colType": "Numeric",
    "colName": "Market"
}, {
    "colIndex": 3,
    "colType": "Numeric",
    "colName": "Sales"
}],
"resultset": [
    ["Europe",    'France',     null,         100],        
    ["Europe",    'Germany',   150,       500],
    ["Europe",    'Austria',   250,       200],
    ["Europe",    'Poland',   220,      100],        
    ["Europe",    'Italy',      120,       200],
    ["Europe",    'Bulgaria',      40,      500],
    ["Europe",    'Romania',      450,      400]
]};

```

I want to transform this dataset in another structure:

```
var data = [{
"country": [
    ['France', null],
    ['Germany', 150],
    ['Austria', 250],
    ['Poland', 220],
    ['Italy', 120],
    ['Bulgaria', 40],
    [Romania', 450]
],
"name": "Market" // this is metadata.colName
},{
"country": [
    ['France', 100],
    ['Germany', 500],
    ['Austria', 200],
    ['Poland', 100],
    ['Italy', 200],
    ['Bulgaria', 500],
    [Romania', 400]
],
"name": "Sales" // this is metadata.colName
}]

```

I tried using some loop variation, but i gave up. Here is my last [fiddle](http://jsfiddle.net/gxg1974/Cmbhx/).

Thank you all for hints or answers.