Во-первых, позвольте мне объяснить, что я пытаюсь выполнить ...
Я хотел бы взять данные, которые я получаю из API, и отфильтровать их по определенному значению.Я опубликую JSON ниже ...
{ assetNo:
{ type: 'string',
format: 'short-text',
minLength: 0,
maxLength: 100,
description: 'Asset ID' },
serialNo:
{ type: 'string',
format: 'short-text',
minLength: 0,
maxLength: 100,
description: 'Serial Number' },
'item:model':
{ type: 'object',
properties: { title: [Object], _id: [Object] },
description: 'Model' },
'location:location':
{ type: 'object',
properties: { title: [Object], _id: [Object] },
description: 'Location ID' },
'item:status':
{ type: 'object',
properties: { title: [Object], _id: [Object] },
description: 'Status' },
imei:
{ type: 'string',
format: 'short-text',
minLength: 0,
maxLength: 100,
description: 'IMEI' },
hostName:
{ type: 'string',
format: 'short-text',
minLength: 0,
maxLength: 100,
description: 'Host Name' },
staticIp:
{ type: 'string',
format: 'short-text',
minLength: 0,
maxLength: 100,
description: 'Static IP' },
mac:
{ type: 'string',
format: 'short-text',
minLength: 0,
maxLength: 100,
description: 'MAC' },
macFriendlyName:
{ type: 'string',
format: 'short-text',
minLength: 0,
maxLength: 100,
description: 'MAC Friendly Name' },
manufacturerWarrantyEndDate:
{ type: 'string',
format: 'date-time',
description: 'Manufacturer Warranty End Date' },
notes:
{ type: 'string',
format: 'long-text',
minLength: 0,
maxLength: 100,
description: 'Notes' },
_id:
{ type: 'string',
format: 'BSON ObjectID',
example: '12344ac4ac34d504212c0db6' } }
Как видите, есть несколько вложенных объектов ... Сглаженные, данные выглядят так ...
{
"assetNo": {
"type": "string",
"format": "short-text",
"minLength": 0,
"maxLength": 100,
"description": "Asset ID"
},
"serialNo": {
"type": "string",
"format": "short-text",
"minLength": 0,
"maxLength": 100,
"description": "Serial Number"
},
"item:model": {
"type": "object",
"properties": {
"title": {
"type": "string",
"format": "short-text",
"description": "title"
},
"_id": {
"type": "string",
"format": "BSON ObjectID",
"example": "12344ac4ac34d504212c0db6"
}
},
"description": "Model"
},
"location:location": {
"type": "object",
"properties": {
"title": {
"type": "string",
"format": "short-text",
"description": "title"
},
"_id": {
"type": "string",
"format": "BSON ObjectID",
"example": "12344ac4ac34d504212c0db6"
}
},
"description": "Location ID"
},
"item:status": {
"type": "object",
"properties": {
"title": {
"type": "string",
"format": "short-text",
"description": "title"
},
"_id": {
"type": "string",
"format": "BSON ObjectID",
"example": "12344ac4ac34d504212c0db6"
}
},
"description": "Status"
},
"imei": {
"type": "string",
"format": "short-text",
"minLength": 0,
"maxLength": 100,
"description": "IMEI"
},
"hostName": {
"type": "string",
"format": "short-text",
"minLength": 0,
"maxLength": 100,
"description": "Host Name"
},
"staticIp": {
"type": "string",
"format": "short-text",
"minLength": 0,
"maxLength": 100,
"description": "Static IP"
},
"mac": {
"type": "string",
"format": "short-text",
"minLength": 0,
"maxLength": 100,
"description": "MAC"
},
"macFriendlyName": {
"type": "string",
"format": "short-text",
"minLength": 0,
"maxLength": 100,
"description": "MAC Friendly Name"
},
"manufacturerWarrantyEndDate": {
"type": "string",
"format": "date-time",
"description": "Manufacturer Warranty End Date"
},
"notes": {
"type": "string",
"format": "long-text",
"minLength": 0,
"maxLength": 100,
"description": "Notes"
},
"_id": {
"type": "string",
"format": "BSON ObjectID",
"example": "12344ac4ac34d504212c0db6"
}
}
Как я могу перебрать эти данные, сгладить вложенные объекты и вернуть только ключ / val для 'type'?
Например ... Я хотел бы вернуть что-то похожееэто ...
{
"assetNo": {
"type": "string",
},
"serialNo": {
"type": "string",
},
"location:location": {
"type": "object",
"type": "string",
},
"_id": {
"type": "string",
},
"item:status": {
"type": "object",
"type": "string",
},
"_id": {
"type": "string",
}
},
"imei": {
"type": "string",
},
"hostName": {
"type": "string",
},
"staticIp": {
"type": "string",
},
"mac": {
"type": "string",
},
"macFriendlyName": {
"type": "string",
},
"manufacturerWarrantyEndDate": {
"type": "string",
},
"notes": {
"type": "string",
},
"_id": {
"type": "string",
}
}
Любая помощь будет принята с благодарностью.
Спасибо!