callJson method
Runs the search for raw JSON arguments and returns the JSON result.
An empty string counts as no arguments. Malformed JSON returns an
{"error": ...} result like any other invalid call.
Implementation
Future<String> callJson(String arguments) async {
Object? decoded;
try {
decoded = arguments.trim().isEmpty ? const {} : jsonDecode(arguments);
} on FormatException {
return jsonEncode(_error('Arguments are not valid JSON.'));
}
if (decoded is! Map<String, Object?>) {
return jsonEncode(_error('Arguments must be a JSON object.'));
}
return jsonEncode(await call(decoded));
}