I know that in most programming scenarios, the preference is for empty collections to null collections when there are 0 elements. However, most languages that consume JSON (like JavaScript) will treat empty lists/objects as true and null ones as false. For example this would be both true and an object in JavaScript:
{
"items_in_stock": {"widgets":10, "gadgets": 5}
}
But this is also true:
{
"items_in_stock": {}
}
And this is false:
{
"items_in_stock": null
}
Is there a convention on empty objects/lists for JSON? And what about for numbers, booleans, and strings?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…