How to use JSON data as Report Data

To use JSON data as report data in Bold Reports®, add a Web API data source in the Report Designer that gets the JSON data from your Web API controller.

  1. Run the application, add NEW DATA and choose WebApi in properties pane.

Choose web api in New Data

  1. Provide the URL in localhost:<portnumber>/api/<webapi controller name>.

Add web api URl

  1. Mention the Web API controller method name and add parameter name and value.

Add parameter name and value

  1. The Report Designer gets the JSON data from the Web API controller into the report dataset.

JSON data values in the report dataset

  1. To see how to use Web API in Report Designer, download the Web API in Report Designer video.

  2. Use the following code sample in controller to get the JSON data.

 public class WebApiServiceController : ApiController
   {
       [HttpPost]
       public object PostParamData([FromBody]string stateCode)
       {
           var data = StoreSales.GetData(stateCode);
           return data;
       }

       [HttpPost]
       public object PostParamInt([FromBody]int id)
       {
           return null;
       }

       [HttpGet]
       public object GetParamData(string stateCode)
       {
           var data = CustomerSales.GetData(stateCode);
           return data;
       }

       [HttpGet]
       public object GetData()
       {
           var data = StoreSales.GetData(string.Empty);
           return data;
       }
   }

   public class CustomerSales
   {
       public int SalesOrderID { get; set; }
       public double TotalDue { get; set; }
       public int CustomerID { get; set; }
       public string FirstName { get; set; }
       public string LastName { get; set; }
       public string StateProvinceCode { get; set; }
       public string City { get; set; }
       public string PostalCode { get; set; }

       public static List<CustomerSales> GetData(string stateCode)
       {
           List<CustomerSales> customerSals = new List<CustomerSales>();
           CustomerSales cusSal = null;

           cusSal = new CustomerSales()
           {
               SalesOrderID = 56893,
               TotalDue = 1934.8329,
               CustomerID = 20668,
               FirstName = "Eric",
               LastName = "Rothenberg",
               StateProvinceCode = "CA",
               City = "Concord",
               PostalCode = "94519"
           };
           customerSals.Add(cusSal);

           return customerSals;
       }
   }

See also