To retrieve the value of `"metric.label.store"`, which is nested within...
August 7, 2025 at 06:18 PM
To retrieve the value of "metric.label.store"
, which is nested within a deeply structured JSON object, you can use standard JavaScript object property accessors. Assuming the JSON data you provided is accessible through a variable, you can do something like the following:
JavaScript Code:
// Assume this is your JSON object coming from `context.panel.data`
const jsonData = {
"state": "Done",
"series": [
{
"refId": "A",
"meta": {
"typeVersion": [0, 0],
"custom": {
"labels": {
"metric.label.bucket": "",
"metric.label.file_name": "CSS-3727-250807112348051-D-J-R.txt.pgp",
"metric.label.file_name_short": "3727-250807112348051-D-J-R",
"metric.label.folder": "RIF",
"metric.label.log": "soft-log",
"metric.label.message": "Successfully uploaded file CSS-3727-250807112348051-D-J-R.txt.pgp to folder RIF in bucket sb-lt-pvt-cps-cpak-prd after 0 retries",
"metric.label.rif_file_name": "CSS-3727-250807112348051-D-J-R.txt.pgp",
"metric.label.store": "3727",
"metric.label.timestamp": "2025-08-07 11:24:08.515",
"metric.name": "value.falcon_CPAK_rif_folder_count_files",
"resource.label.bucket_id": "cpak-log",
"resource.label.location": "northamerica-northeast1",
"resource.label.monitored_resource_type": "global",
"resource.label.project_id": "phc-store-apps",
"resource.label.source_resource_container": "projects/phc-store-apps"
}
}
}
}
]
};
// Access 'metric.label.store'
const storeValue = jsonData.series[0].meta.custom.labels["metric.label.store"];
// Output the result
console.log(storeValue); // Output: "3727"
Explanation:
-
Navigate through the JSON structure:
jsonData.series
gives you the array of series.jsonData.series[0]
accesses the first object in the array.jsonData.series[0].meta
accesses themeta
object.jsonData.series[0].meta.custom
accesses thecustom
object.jsonData.series[0].meta.custom.labels
accesses thelabels
object.- Finally,
jsonData.series[0].meta.custom.labels["metric.label.store"]
retrieves the value of"metric.label.store"
.
-
Bracket notation for nested keys with special characters: Since the key
"metric.label.store"
contains periods (.
), you cannot access it using dot notation (e.g.,labels.metric.label.store
). Instead, use bracket notation:labels["metric.label.store"]
. -
Output: The code retrieves and logs the value
"3727"
(the value of"metric.label.store"
) to the console.
Let me know if you have further questions!
Generate your own explanations
Download our vscode extension
Read other generated explanations
Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node