using System.Collections.Generic;
using System.Text.Json.Serialization;
public static void Main(String[] args)
var requestedColumns = new String[] { "ColumnD", "ColumnB" };
var sampleResponse = new SampleResponse
ColumnC = "AnotherValue",
ColumnD = new AnotherType { Prop1 = "Somevalue" },
PagedResult<SampleResponse> pagedResult = new();
pagedResult.Results.Add(sampleResponse);
var finalResult = new PagedResult<Dictionary<string, Object>>();
finalResult.Page = pagedResult.Page;
finalResult.Total = pagedResult.Total;
finalResult.Results = pagedResult.Results.FilterResults(requestedColumns);
Console.WriteLine(JsonSerializer.Serialize(finalResult));
public class SampleResponse
public string ColumnA { get; set; }
public int? ColumnB { get; set; }
public string ColumnC { get; set; }
public AnotherType ColumnD { get; set; }
public string Prop1 { get; set; }
public static class ResultExtension
public static List<Dictionary<string, Object>> FilterResults<T>(this IList<T> results, string[] propertiesToBeFitered)
List<Dictionary<string, Object>> filteredList = new();
foreach(var result in results)
Dictionary<string, Object> mapping = new();
foreach(var prop in propertiesToBeFitered)
var value = result.GetType().GetProperty(prop)?.GetValue(result);
mapping.Add(prop, value);
filteredList.Add(mapping);
public class PagedResult<T> where T : class
public int Page { get; set; }
public int Limit { get; set; }
public int Total { get; set; }
public IList<T> Results { get; set; }