What is the convention in JSON for empty vs. null?

前端 未结 4 705
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-07 13:33

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

4条回答
  •  旧时难觅i
    2020-12-07 13:46

    There is the question whether we want to differentiate between cases:

    1. "phone" : "" = the value is empty

    2. "phone" : null = the value for "phone" was not set yet

    If we want differentiate I would use null for this. Otherwise we would need to add a new field like "isAssigned" or so. This is an old Database issue.

提交回复
热议问题