parseJsonString static method
Parse JSON string into FunctionCallResponse. Supports key names: "parameters", "args", "arguments".
Implementation
static FunctionCallResponse? parseJsonString(String jsonStr) {
try {
final decoded = jsonDecode(jsonStr);
if (decoded is Map<String, dynamic>) {
final name = decoded['name'] as String?;
if (name == null) {
debugPrint('JsonParsingUtils: JSON missing "name" field');
return null;
}
// Try all known key names for arguments
final args = (decoded['parameters'] as Map<String, dynamic>?) ??
(decoded['args'] as Map<String, dynamic>?) ??
(decoded['arguments'] as Map<String, dynamic>?);
// Use empty map for zero-argument functions (get_time, refresh, etc.)
final resolvedArgs = args ?? <String, dynamic>{};
debugPrint('JsonParsingUtils: Parsed function: $name($resolvedArgs)');
return FunctionCallResponse(name: name, args: resolvedArgs);
}
debugPrint('JsonParsingUtils: JSON missing "name" field or not a Map');
return null;
} catch (e) {
debugPrint('JsonParsingUtils: Failed to decode JSON: $e');
return null;
}
}