Skip to main content

Posts

Showing posts with the label JSON

Handling JSON DateTime format on Asp.Net Core

This is a very simple trick to handle JSON date format on AspNet Core by global settings. This can be applicable for the older version as well. In a newer version by default, .Net depends upon Newtonsoft to process any JSON data. Newtonsoft depends upon Newtonsoft.Json.Converters.IsoDateTimeConverter class for processing date which in turns adds timezone for JSON data format. There is a global setting available for same that can be adjusted according to requirement. So, for example, we want to set default formatting to US format, we just need this code. services.AddMvc() .AddJsonOptions(options => { options.SerializerSettings.DateTimeZoneHandling = "MM/dd/yyyy HH:mm:ss"; });

Data seed through JSON files using EF or any ORM

Last time I had demonstrated a concept for Data Seed through any ORM or MongoDB . The idea is to feed the data to DB at first run or based on condition. The advantage is no one has to manage DB manually with SQL script which feels more natural with Code First approach and every developer can have their own copy with this approach. I am going to extend the same idea by importing data from JSON file. There are few reasons to do through JSON file as we do not want to keep increasing our codes for data import which may end up with   Combined length of user strings used by the program exceeds allowed limit. Try to decrease use of string literals . Also in the case of a huge number of records it does not make sense and with newer development practice JSON feels more natural for data. First please go to  Data seed for the application with EF, MongoDB or any other ORM  as I would be extending same items to allow it through JSON file. It is always a great idea to have a bas...