Two ways to get JSON from DB

@*----------------WAY 1 USING THE ADAPTER ---------------------------*@

@using System.IO

@functions {

    protected string Generate() {

        var adapter = EngineAdapter.Create("Contacts", "People");
        
        adapter.AddResultFields(new[] {"FirstName", "LastName", "PartOfOrganization.Name"});
        
        adapter.AddSearch("Brunton");
    
        MemoryStream ms = new MemoryStream();
        
        adapter.Export(ms, new EngineCore.Data.ExportFormats.Json(), ExportOptions.None);         
        
        ms.Seek(0, SeekOrigin.Begin);         
        
        using (StreamReader sr = new StreamReader(ms)) {             
            return sr.ReadToEnd();
        };
    
    }
    
}

<span>@Generate()</span>

@*----------------WAY 2 USING A LISTER ---------------------------*@

@using System;
@using System.Text;

@{  string whereFilter = DateTime.Now.Year.ToString();      //if no filter, default to this year
    StringBuilder sb = new StringBuilder();
}

@if(!String.IsNullOrEmpty(Request.QueryString["filter"])){ 
    whereFilter = Request.QueryString["filter"];
}

@BRT.Lister(tableId: "Content", viewId: "RemitFunds",
condition: "<And><Eq FieldId=\"FundActive\" Value=\"false\"/><Or><IsNull FieldId=\"StartDate\"/><Range FieldId=\"StartDate\" StartValue=\"1/1/" + whereFilter + " 12:00:00 AM\" EndValue=\"12/31/" + whereFilter + " 12:00:00 AM\"/></Or><Or><IsNull FieldId=\"EndDate\"/><Range FieldId=\"EndDate\" StartValue=\"1/1/" + whereFilter + " 12:00:00 AM\" EndValue=\"12/31/" + whereFilter + " 12:00:00 AM\"/></Or></And>",
sortFields: new SortFieldMeta[] {new SortFieldMeta() {FieldId = "Title"}},
fields: new[] {"Title","Summary"},
pageSize: 500,
template: 
@<div>
@{sb.Append("[");
    StringBuilder DisplayName = new StringBuilder();
    foreach(EngineRecord record in item) {
        if(!record.IsDBNull("Title")) {
            sb.Append("{ \"id\":" + record.Id.ToString() + ", \"name\": \"" + record["Title"].ToString() + " " + record["Summary"].ToString() + " \"},");
        }
    }       
    sb.Length--;        // remove trailing comma
    sb.Append("]");
}
@BRT.Raw(sb.ToString())
</div>)