I am currently building a tool that should extract the Core Web Vitals metrics of a URL.
With the API i can receive a JSON object wich i can access with JSONPath.
I would like to use a forEach loop to input the data into the HTML-fields.
Now my question is, how can i access child nodes of a JSON without using their names.
document.querySelectorAll('[data-section^="cww"]').forEach((nodes, index) => {
console.log(values.body.record.metrics);
});
{
"key": {
"origin": "https://developer.mozilla.org"
},
"metrics": {
"cumulative_layout_shift": {
"histogram": [
{
"start": "0.00",
"end": "0.10",
"density": 0.9377813344003197
},
{
"start": "0.10",
"end": "0.25",
"density": 0.039611883565069506
},
{
"start": "0.25",
"density": 0.022606782034610366
}
],
"percentiles": {
"p75": "0.01"
}
},
"first_contentful_paint": {
"histogram": [
{
"start": 0,
"end": 1800,
"density": 0.9419767907162874
},
{
"start": 1800,
"end": 3000,
"density": 0.03741496598639458
},
{
"start": 3000,
"density": 0.02060824329731889
}
],
"percentiles": {
"p75": 841
}
},
"first_input_delay": {
"histogram": [
{
"start": 0,
"end": 100,
"density": 0.9863863863863849
},
{
"start": 100,
"end": 300,
"density": 0.008308308308308296
},
{
"start": 300,
"density": 0.0053053053053052955
}
],
"percentiles": {
"p75": 5
}
},
"largest_contentful_paint": {
"histogram": [
{
"start": 0,
"end": 2500,
"density": 0.9460068054443531
},
{
"start": 2500,
"end": 4000,
"density": 0.03467774219375491
},
{
"start": 4000,
"density": 0.019315452361889692
}
],
"percentiles": {
"p75": 1135
}
}
}
}