Guest Post

Different JSON files and its uses in ASP.NET Core

What is ASP.NET Core?

Dot Net Core is a free open-source platform that was developed by Microsoft. ASP.NET Core is a cross-platform that supports mostly all operating systems like macOS, Windows, and Linux.

Being recognized as a remarkable web development platform among the technologies of Microsoft, .Net Core is embedded with a lot of features that help build the cloud-based application, device applications. Just have a quick look at its characteristics that make it an efficient platform for the developers.

  • Cross-platform support
  • Offers Command-line tools
  • Familiar with the frameworks like – .Net framework, Mono, Xamarin
  • .NET core is an Open source platform so there is no need to purchase any license
  • Easy to install

Why should you use the .NET core?

Microsoft launch two major frameworks to develop software- .NET framework &.NET core. .NET Core is modern, multipurpose, multi-platform, easy, and fast software. Some advantages listed below would help you know why the .NET core is the chosen platform for development.

  • .NET Core is rewritten and is the latest update of its .net Framework.
  • .NET Core works across multiple platforms like Windows, Mac, and Linux operating systems

List out the available JSON file in asp.net core: –

.NET core has mainly six configuration JSON files available

  1. global.json
  2. launchsettings.json
  3. appsettings.json
  4. bundleconfig.json
  5. project.json
  6. bower.json

(1)  global.json

Example

we will define the solution level settings in global.json file.
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.2.0-preview2-003321"
}
}

Projects − Projects property defines the location of source code for your solution. It specifies two locations for projects in the solution: src and test.src which contains actual application and test.

(2)  launchsettings.json

The important point that you need to know is this launchSettings.json file is only used within the local development machine. That means this file is not required when we publish the asp.net core application to the production server.

launchSettings.json file supports a number of configuration functions.
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50944/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ASPCoreMVCHelloWorld": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"kestrel": {
"commandName": "kestrel",
"sdkVersion": "dnx-clr-win-x86.1.0.0-preview2-003121"
}
}
}

(3)  appsettings.json

appsettings.json file is an application configuration file that was created by a system that is used to store configuration settings like database connections strings, other application scope global variables, etc. When we open the ASP.NET appsettings.json file, then you can able to see the below code by default which is created by the system.

{
"description": "Description",
"enforceCompleteSnapshots": "Specify true to require an
explicit version for each component",
"name": "Application name or ID",
"notificationScheme": "Notification scheme"
}

(4)  bundleconfig.json

When we create new project at that time this bundleconfig.json this file is created by the system. You can bundle your JavaScript using the CLI command by providing an entry file and output path.bundleconfig.json  will automatically resolve all dependencies from import and require and bundle them into a single output together with your app’s script because that’s just the bare minimum it can do.

[
{
"outputFileName": "wwwroot/css/site.min.css",
// the array of relative input file paths. Globing patterns supported
"inputFiles": [
"wwwroot/css/site.css"
]
},
{
"outputFileName": "wwwroot/js/site.min.js",
"inputFiles": [
"wwwroot/js/site.js"
],
// Optionally specify minification options
"minify": {
"enabled": true,
"renameLocals": true
},
// Optinally generate .map file
"sourceMap": false
}
]

(5)  project.json

The package.json is a JSON text file that contains the metadata of your project. This contains all the properties to identify the project such as its name and the current version of the module, license, author of the project, its description, etc. It also contains a list of all the dependencies which can be used in the project. This makes the work very easier for us, with the help of the project.json file, we know our team members or friends can know about our project and the modules that we used to accomplish it, simply by looking at this file. Project.json is generated by a system file that is created for each .xaml file marked as Main in the project folder. Project.json file holds varied information, like project dependencies, or web services loaded in libraries. package.json  store web services related information.

{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": ["dotnet5.6", "portable-net45+win8"]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": ["wwwroot", "web.config" ]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath%
--framework %publish:FullTargetFramework%" ]
}
}

(6) Bower.json

Bower may be a package manager for client-side libraries. It is almost like NuGet, except for JavaScript and CSS. You’ll recall that in recent versions of Visual Studio, its templates for ASP.NET applications won’t to include libraries like jQuery; well this is often not the case, as NuGet is left for .NET, and JavaScript and CSS now use Bower.

Firstly, JSON Browser will prettify JSON documents to make them much more readable. Also, it will grab the schema referenced in the HTTP header i.e. “Content-Type: application/JSON; profile=/schema.json“. It can then use this to provide you with the context of the schema and sub-schemas and add hyperlinks to other documents or pages.

We hope this will be used for developing browsable, intuitive, and self-documenting APIs using JSON schema.

{
"name": "My Project",
"version": "1.0.0",
"authors": [
"Jobin"
],
"description": "My first bower project.",
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"angular": "~1.4.3"
}
}

Conclusion:

This blog will be helpful in understanding the concept of various types of .JSON file in ASP.NET Core. This is used to store application information and web service information. Here, in this article, we have also discussed the significant factors of the .JSON file.

A Seasoned technocrat with years of experience building technical solutions for various industries using Microsoft technologies. Wish sharp understanding and technical acumen, have delivered hundreds of Web, Cloud, Desktop and Mobile solutions and is heading the technical department at ASP.NET Core Software Company – iFour Technolab Pvt. Ltd.