You are right that there is no simple equivalent.
If you use JSON documents with line separators instead of a JSON array, this becomes pretty simple:
List<Document> getDocumentsFromLineDelimitedJson(final String lineDelimitedJson) { BufferedReader stringReader = new BufferedReader( new StringReader(lineDelimitedJson)); List<Document> documents = new ArrayList<>(); String json; try { while ((json = stringReader.readLine()) != null) { documents.add(Document.parse(json)); } } catch (IOException e) {
For example, this call
System.out.println(getDocumentsFromLineDelimitedJson("{a : 1}\n{a : 2}\n{a : 3}"));
will print:
[Document {{a = 1}}, Document {{a = 2}}, Document {{a = 3}}]
source share