Please, by using the following code by @Nimrod (see this thread), can anybody tell me how to account for missing values when converting an array of objects into csv?
var csv = []
if (items.length) {
var keys = Object.keys(items[0])
csv.push(keys.join(','))
items.forEach(item => {
let vals = keys.map(key => item[key] || '')
csv.push(vals.join(','))
})
}
csv = csv.join('\n')
The items are Postman response data:
const items = pm.response.json().data
.map((data) => ({
text: data.text,
created_at: data.created_at,
author_id: data.author_id,
id: data.id,
}))
The code by @Nimrod works so far. However, if there is no response data I want a csv file only with the text "no tweets".
Thank you in advance!