addDocumentsJson method
Add a list of documents by given documents
and optional primaryKey
parameter.
- The passed
documents
must be a valid JSON string representing an array of objects.
If the index does not exist, tries to create a new index and adds documents.
Implementation
Future<Task> addDocumentsJson(String documents, {String? primaryKey}) {
final decoded = jsonDecode(documents);
if (decoded is List<Object?>) {
final casted = decoded.whereType<Map<String, Object?>>().toList();
return addDocuments(casted, primaryKey: primaryKey);
}
throw MeiliSearchApiException(
"Provided json must be an array of documents, consider using addDocumentsNdjson if this isn't the case",
);
}