jsonDecodeList function
Decodes a JSON string into a List<dynamic>, always returning a list.
Returns an empty list for invalid or empty input.
final result = jsonDecodeList('[1, 2, 3]');
print(result); // [1, 2, 3]
final emptyResult = jsonDecodeList('');
print(emptyResult); // []
@ai Use when you need a list result regardless of input validity.
Implementation
List<dynamic> jsonDecodeList(final dynamic json) {
if (json case final List list) return list;
final jsonString = jsonDecodeString(json);
if (jsonString.isEmpty) return [];
return switch (jsonDecode(jsonString)) {
final List list => list,
_ => [],
};
}