I need to read a json file and print the data on a table The json file has a lot of objects, and objects inside objects, arrays...
Example of the json file
[
{
"id_transaction": 116,
"company": "ABC",
"verified": true,
"date": "2019-04-09T13:31:20.429Z",
"bio_data": {
"id": "string",
"data": "string",
"digital": [
{
"name": "value1",
"digital": ""
},
{
"name": "value2",
"digital": "value2"
},
{
"name": "",
"digital": "value3"
}
]
},
"info_data": {
"value1": "value1",
"value2": "",
"value3": "",
"value4": "value4",
"value5": 1.0,
"value6": ""
}
}
]
Any data of this json file can be null, the objects bio_data
and info_data
can be null, the array digital
can be null, and the others simple atributs (company
, date
etc..) can be null.
What's the best way to deal with null values?
For now, I was dealing with each case, changing the null value to -
, but that's not the most intelligent way. Follow an example:
id_transaction !== null ? id_transaction : ' - '
info_data !== null ? info_data.value1 : ' - '
bio_data.digital[0] !== undefined ? bio_data.digital[0].name] : '-'
How can I create a fucntion to deal with it? Or exists a better way to deal with it (i'm using react)?