diff --git a/arangosh/Import/ImportFeature.cpp b/arangosh/Import/ImportFeature.cpp index 9d14335533..0ca2930c9f 100644 --- a/arangosh/Import/ImportFeature.cpp +++ b/arangosh/Import/ImportFeature.cpp @@ -115,7 +115,7 @@ void ImportFeature::collectOptions( new DiscreteValuesParameter(&_createCollectionType, types)); - std::unordered_set imports = {"csv", "tsv", "json", "auto"}; + std::unordered_set imports = {"csv", "tsv", "json", "jsonl", "auto"}; options->addOption( "--type", "type of import file", @@ -230,12 +230,8 @@ void ImportFeature::start() { } std::string extension = match[1].str(); - if (extension == "json") { - _typeImport = "json"; - } else if (extension == "csv") { - _typeImport = "csv"; - } else if (extension == "tsv") { - _typeImport = "tsv"; + if (extension == "json" || extension == "jsonl" || extension == "csv" || extension == "tsv") { + _typeImport = extension; } else { LOG_TOPIC(FATAL, arangodb::Logger::FIXME) << "Unsupported file extension '" << extension << "'"; FATAL_ERROR_EXIT(); @@ -386,9 +382,9 @@ void ImportFeature::start() { arangodb::import::ImportHelper::TSV); } - else if (_typeImport == "json") { + else if (_typeImport == "json" || _typeImport == "jsonl") { std::cout << "Starting JSON import..." << std::endl; - ok = ih.importJson(_collectionName, _filename); + ok = ih.importJson(_collectionName, _filename, (_typeImport == "jsonl")); } else { diff --git a/arangosh/Import/ImportHelper.cpp b/arangosh/Import/ImportHelper.cpp index 122865e526..1feea0da81 100644 --- a/arangosh/Import/ImportHelper.cpp +++ b/arangosh/Import/ImportHelper.cpp @@ -280,7 +280,8 @@ bool ImportHelper::importDelimited(std::string const& collectionName, } bool ImportHelper::importJson(std::string const& collectionName, - std::string const& fileName) { + std::string const& fileName, + bool assumeLinewise) { _collectionName = collectionName; _firstLine = ""; _outputBuffer.clear(); @@ -309,6 +310,11 @@ bool ImportHelper::importJson(std::string const& collectionName, bool isObject = false; bool checkedFront = false; + if (assumeLinewise) { + checkedFront = true; + isObject = false; + } + // progress display control variables int64_t totalRead = 0; double nextProgress = ProgressStep; @@ -345,8 +351,7 @@ bool ImportHelper::importJson(std::string const& collectionName, if (!checkedFront) { // detect the import file format (single lines with individual JSON - // objects - // or a JSON array with all documents) + // objects or a JSON array with all documents) char const* p = _outputBuffer.begin(); char const* e = _outputBuffer.end(); diff --git a/arangosh/Import/ImportHelper.h b/arangosh/Import/ImportHelper.h index 11f0278845..91443dfade 100644 --- a/arangosh/Import/ImportHelper.h +++ b/arangosh/Import/ImportHelper.h @@ -79,7 +79,8 @@ class ImportHelper { ////////////////////////////////////////////////////////////////////////////// bool importJson(std::string const& collectionName, - std::string const& fileName); + std::string const& fileName, + bool assumeLinewise); ////////////////////////////////////////////////////////////////////////////// /// @brief sets the action to carry out on duplicate _key diff --git a/arangosh/Shell/V8ClientConnection.cpp b/arangosh/Shell/V8ClientConnection.cpp index 7ba5160e44..c4ea18be4b 100644 --- a/arangosh/Shell/V8ClientConnection.cpp +++ b/arangosh/Shell/V8ClientConnection.cpp @@ -1024,7 +1024,7 @@ static void ClientConnection_importJson( std::string fileName = TRI_ObjectToString(isolate, args[0]); std::string collectionName = TRI_ObjectToString(isolate, args[1]); - if (ih.importJson(collectionName, fileName)) { + if (ih.importJson(collectionName, fileName, false)) { v8::Handle result = v8::Object::New(isolate); result->Set(TRI_V8_ASCII_STRING("lines"),