I am not so into JavaScript and I have the following problem. To solve this problem I can use only pure old JavaScript (not library or framework).
I have a JSON document like this:
{
"Commodity": {
"CommodityInMarket": {
"market_info": {
"market_id": 5,
"market_name": "Tambacounda Market N2",
"available_market_count": 1
},
"commodity_info": {
"commodity_details_id": 1,
"commodity_name_en": "Rice-Asia",
"commodity_name": "Rice-Asia",
"image_link": "https://firebasestorage.googleapis.com/v0/b/fao-digital-services-portfolio.appspot.com/o/img%2Ficons%2Fagrimarket%2Fcommodity%2Friz.png?alt=media&token=c35e7648-1793-423b-acd2-52d8a1e58c53",
"description": "Rice-Asia"
},
"price_info": {
"price_serie_id": 29,
"today_avg_price": 9.3000,
"yesterday_avg_price": 9.6000,
"currency": "XOF",
"measure_unit": "kilogram"
}
}
}
}
As you can see this document contains a Commodity object.
In some case it is a simple object (as in the previous code snippet), in some other case it can be an array (this document is returned by a service in this way), so something like this:
{
"Commodity": {
"CommodityInMarket": [{
.....................................
.....................................
.....................................
},
{
.....................................
.....................................
.....................................
}]
}
}
How can I check if this Commodity object into my JSON document is a simple object or an array? I need to do something like this:
If it is a simple object put true into a boolean variable. How can I implement this behavior?