Line data Source code
1 : import 'dart:convert';
2 :
3 : import 'package:at_utils/at_logger.dart';
4 :
5 : class JsonUtils {
6 0 : static var logger = AtSignLogger('JsonDecode');
7 :
8 : /// Returns null when [jsonString] is null or empty.
9 : /// For a valid json string decodes and returns the decoded json, else null
10 0 : static dynamic decodeJson(String? jsonString) {
11 0 : if (jsonString == null || jsonString.isEmpty) {
12 0 : logger.severe('Failed to decode jsonString. Received empty string');
13 : return;
14 : }
15 : dynamic map;
16 : try {
17 0 : map = jsonDecode(jsonString);
18 0 : } on FormatException catch (e) {
19 0 : logger.severe('Failed to decode jsonString : $jsonString Error : $e');
20 : }
21 : return map;
22 : }
23 : }
|