I'm trying out the new server-side javascript API in MarkLogic 8. I'm mainly interested in search. The examples I've seen start by saving JSON into the database and then search the native JSON. That is not my use case because my company has tons of native XML already stored in the database. I want to use javascript to search for documents and I want the search results in JSON.
Is that even possible from javascript? When I run the code below, (modified from one of the examples) the result is an array of string, where each string is a complete XML document. Not what I want. Is there an API call to convert each result to JSON?
var count = 0;
var results = [];
for (var result of cts.search(cts.wordQuery("value1"))) {
count++;
results.push(result);
};
results.push(fn.concat("Count = ", count));
results;