I am using "react-json-to-csv" in order to save my json data into a csv file, the problem is with the nested objects because the csv export header is broken, displaying alternate data due to those nested objects. For Example this is my json data:
[
{
"id": "997",
"source": "wired",
"title": "testing title",
"www": {
"wwwId": 918,
"wwwName": "Deprecated wire)"
},
"css": 7.3,
"wrongAdded": "true",
"paths": [
{
"name": "client",
"version": "1.9.2",
"description": "testing",
"resolvePath": {
"name": "ares",
"isFsfLibre": true,
"isold": false
},
"externalPath": [
{
"type": "a",
"url": "was"
},
{
"type": "q",
"url": "wss"
},
{
"type": "x",
"url": "was"
}
],
"project": {
"name": "Testing",
"version": "001",
"active": true
},
"usedBy": 0,
"isInternal": false
}
],
"Count": 0
}, ... and so on
]
and in this way I am getting my api data:
const [stateData, setData] = useState({infoData:[]});
.......
function callingApis() {
const promises = urls.map(url => axios.get(url, { headers }));
Promise.all(promises).then(responses => {
let data = [];
responses.forEach(response => {
data = data.concat(response.data);
});
setData(data);
});
};
Maybe someone have a better Ideea about how to do that?
Or it is possible to store in a variable some pieces from the json object like:
const filteredData = [
{"id": stateData.id},
{"source": stateData.source},
{"pathName": stateData.paths.name}
{"pathDescription": stateData.paths.description},
and so on ...
]
But I guess there is a need to do .map() over the data before filtering ?
and at the end to export it to "react-json-to-csv".
<CsvDownload data={filteredData} />