Below JSOM code is iterating through sharepoint list items. This will not be efficient if the CAML query results are in thousands. Is there any way to convert the query results directly into JSON without looping and REST queries.

while (listItemEnumerator.moveNext()) 
  var oListItem = listItemEnumerator.get_current();
  listItemInfo += '\nID: ' + oListItem.get_id() +
             '\nTitle: ' + oListItem.get_item('Title') +
             '\nDLastName: ' + oListItem.get_item('DLastName') +
             '\nDLastName: ' + oListItem.get_item('DLastName');

1 Answer 1


Umh, afaik that's not possible. I don't know your reasons for why you can't use REST, but you could try looking into the onExecutingWebRequest etc on the SP.ClientContext object and abort the initial request, and then do your own request with the payload JSOM have generated. Never used it like that myself, but I have a simple example of what I'm talking about that you could play around with:

(function() { 

    var ctx = SP.ClientContext.get_current();
    var list = ctx.get_web().get_lists().getByTitle("ListTitle");
    var items = list.getItems(SP.CamlQuery.createAllItemsQuery());
    ctx.load(items, "Include(ID, Title)");

    // abort the request

    ctx.onExecutingWebRequest = function(webRequest,e) {
        var waitForExecutor = setInterval(function() { 
            if(typeof  webRequest.get_webRequest() != null) {

                    url: webRequest.get_webRequest().get_url(),
                    data: webRequest.get_webRequest().get_body(),
                    type: "POST",
                    headers: {
                        "Content-Type": webRequest.get_webRequest().get_headers()["Content-Type"], 
                        "X-RequestDigest": webRequest.get_webRequest().get_headers()["X-RequestDigest"]
                    success: function(data) {
                        if(data.length) {
                            var collection = data.filter(function(item) { 
                                if(item._ObjectType_ === "SP.ListItemCollection") {
                                    return item._Child_Items_;
                            if(collection.length) {
                                var json = JSON.stringify(collection[0]._Child_Items_);
                    error: function(err) {


    ctx.executeQueryAsync( function() {
        console.log("Should not enter this function")
    }, function(s,a) {
        console.log("Should enter if aborted");

  • REST will not support complex CAML queries which involves multiple list JOINS and Projections that's why I am using JSOM
    – user17274
    Feb 14, 2018 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.