我從包含JSON陣列,我試圖刪除除標題,列和searchSourceJSON所有元素的API如下回應:如何從此JSON數組中刪除不需要的元素?
"hits": [
{
"_index": ".example_demo",
"_type": "search",
"_id": "demo-Media-Integration-Enabled",
"_score": 1,
"_source": {
"title": "demo Media Integration - Enabled",
"description": "",
"hits": 0,
"columns": [
"_source"
],
"sort": [
"timestamp",
"asc"
],
"version": 1,
"exampleSavedObjectMeta": {
"searchSourceJSON": "{\"index\":\"[demo-]YYYY.MM\",\"highlight\":{\"pre_tags\":[\"@[email protected]\"],\"post_tags\":[\"@/[email protected]\"],\"fields\":{\"*\":{}},\"fragment_size\":2147483647},\"filter\":[{\"meta\":{\"negate\":false,\"index\":\"[demo-]YYYY.MM\",\"key\":\"_type\",\"value\":\"Media Integration\",\"disabled\":false},\"query\":{\"match\":{\"_type\":{\"query\":\"Media Integration\",\"type\":\"phrase\"}}}},{\"meta\":{\"negate\":false,\"index\":\"[demo-]YYYY.MM\",\"key\":\"Action\",\"value\":\"Enable\",\"disabled\":false},\"query\":{\"match\":{\"Action\":{\"query\":\"Enable\",\"type\":\"phrase\"}}}}],\"query\":{\"query_string\":{\"query\":\"*\",\"analyze_wildcard\":true}}}"
}
}
},
{
"_index": ".example_demo",
"_type": "search",
"_id": "demo-Media-Import-True",
"_score": 1,
"_source": {
"title": "demo Media Import - True",
"description": "",
"hits": 0,
"columns": [
"FormFactor",
"_type",
"Identity"
],
"sort": [
"_type",
"asc"
],
"version": 1,
"exampleSavedObjectMeta": {
"searchSourceJSON": "{\"index\":\"[demo-]YYYY.MM\",\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"*\"}},\"highlight\":{\"pre_tags\":[\"@[email protected]\"],\"post_tags\":[\"@/[email protected]\"],\"fields\":{\"*\":{}},\"fragment_size\":2147483647},\"filter\":[{\"meta\":{\"disabled\":false,\"index\":\"[demo-]YYYY.MM\",\"key\":\"_type\",\"negate\":false,\"value\":\"Media Import\"},\"query\":{\"match\":{\"_type\":{\"query\":\"Media Import\",\"type\":\"phrase\"}}}},{\"meta\":{\"negate\":false,\"index\":\"[demo-]YYYY.MM\",\"key\":\"Successful\",\"value\":\"True\",\"disabled\":false},\"query\":{\"match\":{\"Successful\":{\"query\":\"True\",\"type\":\"phrase\"}}}}]}"
}
}
}
]
有人能幫助我弄清楚如何刪除不需要的元素從這個使用JavaScript的JSON文件?
編輯︰答:謝謝大家的偉大的信息!
你可以只創建一個新的JS對象,並從您想保留 – LiverpoolOwen
如果你只在短短的興趣屬性取值幾個屬性,爲什麼當你只需用你正在尋找的屬性創建一個新的對象時,它們都會從這個大數據結構中剝離出來? 'hits.map(hit =>({title:hit._source.title,/ * ... * /}))' – Will