How do you distinguish an empty candidate list from a missing list?

json_array_length returns the number of items in an array, NULL for an absent path, and can return zero for a present non-array value.

SQLite example and interpretation

An empty list legitimately has zero candidates. A string in the wrong field can also produce zero, so validate the field type first.

SELECT json_array_length('{"c":[]}','$.c'),json_array_length('{}','$.c'),json_array_length('{"c":"bad"}','$.c');

Result [[0, null, 0]]

中文

统计模型返回候选项时,空数组和缺字段如何区分?

json_array_length 对数组返回长度,对缺失路径返回 NULL,对存在的非数组值可返回零。

SQLite 示例与适用条件

空清单是合法的零候选。类型错误的字符串也可能显示零,所以统计前应检查 json_type。

SELECT json_array_length('{"c":[]}','$.c'),json_array_length('{}','$.c'),json_array_length('{"c":"bad"}','$.c');

结果 [[0, null, 0]]

References / 参考来源

Keep reading / 继续阅读