const json_data =
{
"headers":
[
"FirstValue",
"SecondValue",
"ThirdValue",
"FourthValue",
"FifthValue",
"NumberOne",
"NumberTwo"
],
"rows":
[
[
"_2222_",
"_first_",
"CPV",
"unknown",
"_2222_",
92310.8671,
5226.386074028007
],
[
"_2222_",
"_first_",
"WWW",
"known",
"_2222_",
92310.8671,
5226.386074028007
],
[
"_2222_",
"_second_",
"VVV",
"unknown",
"_2222_",
92310.8671,
null
],
[
"_2222_",
"_third_",
"VVV",
"unknown",
"_2222_",
92310.8671,
5226.386074028007
],
[
"_1111_",
"_first_",
"VVV",
"unknown",
"random",
197977.2658,
36169.2693355163
],
[
"_1111_",
"_first_",
"WWW",
"unknown",
"random",
197977.2658,
36169.2693355163
],
[
"_1111_",
"_second_",
"VVV",
"unknown",
"random",
197977.2658,
36169.2693355163
],
[
"_1111_",
"_third_",
"WWW",
"display",
"random",
26536.9836,
1957.2823939366558
]
]
};
// convert into array of objects [{FirstValue: 'abc', SecondValue: 'abc', ...}, ...]
let converted = json_data.rows.map(e => e.reduce( (accumulated, val, idx) => ({...accumulated, [json_data.headers[idx]]: val}), {} ) );
// console.log('CONVERTED\n', converted);
// to get an ordered and filtered output, let's do some stuff...
const ordinal = ['_first_', '_second_', '_third_'];
// get an ordered unique array of the first two fields of each row, e.g. [['_1111_', '_first_'], ...]
// using a Set of JSON-Strings converted back to an array.
let unique01 = Array.from( new Set(json_data.rows.map((val, i) => JSON.stringify(val.slice(0,2)))) )
.map(JSON.parse)
// order by first field, then by second field
.sort( (e1,e2) => e2[0] !== e1[0] ? e2[0] < e1[0] : ordinal.indexOf(e2[1]) < ordinal.indexOf(e1[1]) )
;
// console.log('UNIQUE\n', unique01);
let e = document.getElementById('data-container');
// output filtered data sets as JSON
for(let v of unique01)
e.insertAdjacentHTML('beforeend',
` <h1>${v.join(' - ')}</h1>${converted.filter( e => e.FirstValue === v[0] && e.SecondValue === v[1] )
.reduce( (aggregated,o)=>`${aggregated}
<div>${JSON.stringify(o)}</div>`
, '')
}
` );
<div id="data-container"></div>