commandJson method
Apply the JSON-encoded write command to the first registered root;
returns the result as a JSON string ({ok, message}).
Implementation
Future<String> commandJson(String command) async {
final root = _roots.values.isEmpty ? null : _roots.values.first;
if (root == null) {
return jsonEncode(<String, Object?>{'ok': false, 'message': 'No root.'});
}
final Map<String, Object?> parsed;
try {
parsed = (jsonDecode(command) as Map).cast<String, Object?>();
} catch (_) {
return jsonEncode(<String, Object?>{
'ok': false,
'message': 'Malformed command.',
});
}
return jsonEncode(await root.debugApplyCommand(parsed));
}