JSON.Config 1.1.1

dotnet add package JSON.Config --version 1.1.1
                    
NuGet\Install-Package JSON.Config -Version 1.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JSON.Config" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JSON.Config" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="JSON.Config" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add JSON.Config --version 1.1.1
                    
#r "nuget: JSON.Config, 1.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package JSON.Config@1.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=JSON.Config&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=JSON.Config&version=1.1.1
                    
Install as a Cake Tool

JSON.Config NuGet

So this is you trying to handle all these missed up config files written in xml.

<img src="https://fat.gfycat.com/OrangeVastAntarcticgiantpetrel.gif" width="600" height="300"/>

With JSON.Config, say goodbye to missed up configurations. And you can have your configs placed in one place where you can have all your applications access it and read the needed configs.

Currently the Package are quite simple, and we hope that we can advanced it even more. It uses the super fast Jil as it's JSON serializer/Deserialize.

Getting Started

Very simple, just go to NuGet Package Console Manager and Install JSON.Config:

Install-Package JSON.Config

After that, Just create a new instance of the JsonConfigurationSource Class and you are all set to go. You will have to pass the source of the JSON for the JsonConfigurationSource so it can read it for you. Remember that you can pass either a web url, a local file or database as follow:

Local File:

JsonConfigurationSource source = new JsonConfigurationSource(newJsonConfigurationDataSource(SourceType.FilePath,AppDomain.CurrentDomain.BaseDirectory+@"config.json"));

Web URL:

JsonConfigurationSource source = new JsonConfigurationSource(new JsonConfigurationDataSource(SourceType.Url,"https://jsonplaceholder.typicode.com/posts/1"));

Database (Please check the notes!):

JsonConfigurationSource source = new JsonConfigurationSource(new JsonConfigurationDataSource(SourceType.Database,"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=JSONConfig;Data Source=."));

After setting the source of the JSON, just simply call the Read Method so it give you back the value you desired:

var result = source.Read("connectionString");

The data returned inside the result is from type JsonConfigurationData, which contains the following:

public class JsonConfigurationData : IJsonConfigurationData
	{
	    public JsonConfigurationData()
	    {
	        Configs = new List<Dictionary<string, string>>();
	    }
        /// <summary>
        /// List of the configs read from the json file
        /// </summary>
	    public List<Dictionary<string, string>> Configs { get; set; }
        /// <summary>
        /// Count of the configs
        /// </summary>
	    public int Count { get; set; }
        /// <summary>
        /// An exception if an error happened
        /// </summary>
	    public Exception Error { get; set; }
        /// <summary>
        /// is the retrieval/send process has successes or failed
        /// </summary>
	    public bool IsSuccessed { get; set; }
        /// <summary>
        /// Get the first occurrence of the value
        /// </summary>
        public string Configuration
        {
            get
            {
                if (!IsSuccessed) return "";
                return Configs.Count > 0 ? Configs.First().First().Value : "";
            }
        }
    }

Now either use Configs or Configuration to access the value. In case of error you will find the Exception details inside the Exception property and the IsSuccessed flag will be false.

Notes: For the Database source, you can use the following sample sql to create a sample table and the stored procedure to get the value for you.

Sql Table Sql Stored Procedure

Happy Coding 😃

Please support our site TutorialsXL.com which contains online courses for programming and supports open source projects like this!

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.5

    • Jil (>= 2.15.4)

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 1,669 2/24/2018
1.1.0 1,479 2/23/2018
1.0.0 2,880 12/29/2017

-Adding a new better structure for the project.
     -Now you can read web urls, from database, from file
     -Also, quick access the property you need