{"id":94916,"date":"2023-08-29T08:17:39","date_gmt":"2023-08-29T06:17:39","guid":{"rendered":"https:\/\/code-maze.com\/?p=94916"},"modified":"2023-08-29T08:22:35","modified_gmt":"2023-08-29T06:22:35","slug":"aspnetcore-get-json-array-using-iconfiguration","status":"publish","type":"post","link":"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/","title":{"rendered":"How to Get a JSON Array Using IConfiguration in ASP.NET Core"},"content":{"rendered":"<p>In this article, we will explore how to get a JSON array using IConfiguration. In modern web applications, JSON is a widely used data interchange format due to its lightweight nature and ease of use. When developing an ASP.NET Core application, it is common to store configuration data, such as settings and connection strings, in JSON files like appsettings.json.<\/p>\n<p>ASP.NET Core provides the IConfiguration interface for accessing configuration data from various sources, including JSON files.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/aspnetcore-features\/ReadArraysFromAppSettings\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s dive in.<\/p>\n<h2>JSON File Structure and Sample Data<\/h2>\n<p>Before starting, let&#8217;s consider the file structure and the sample JSON data stored in the appsettings.json file to demonstrate how to get a JSON array using <code>IConfiguration<\/code>. The JSON file includes arrays and nested arrays as well.<\/p>\n<p>Let&#8217;s see what is the structure of the appsettings.json file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"json\">{\r\n  \"Logging\": {\r\n    \"LogLevel\": {\r\n      \"Default\": \"Information\",\r\n      \"Microsoft.AspNetCore\": \"Warning\"\r\n    }\r\n  },\r\n  \"AllowedHosts\": \"*\",\r\n  \"AppSettings\": {\r\n    \"Users\": [\r\n      {\r\n        \"Id\": 1,\r\n        \"Name\": \"John Doe\",\r\n        \"Role\": \"Admin\"\r\n      },\r\n      {\r\n        \"Id\": 2,\r\n        \"Name\": \"John Smith\",\r\n        \"Role\": \"User\"\r\n      }\r\n    ],\r\n    \"Groups\": [\r\n      {\r\n        \"Id\": 1,\r\n        \"Name\": \"Developers\",\r\n        \"Members\": [\r\n          {\r\n            \"Id\": 1,\r\n            \"Name\": \"John Doe\"\r\n          },\r\n          {\r\n            \"Id\": 2,\r\n            \"Name\": \"John Smith\"\r\n          }\r\n        ]\r\n      }\r\n    ]\r\n  }\r\n}<\/pre>\n<p>On the first level, we create an <code>AppSettings<\/code> object with two arrays, <code>Users<\/code> and <code>Groups<\/code>. The array <code>Users<\/code> has other objects with simple properties while the array <code>Groups<\/code>\u00a0has objects where one of the properties, <code>Members<\/code>, is another array of objects.\u00a0<\/p>\n<h2>Get JSON Array Using IConfiguration With GetSection() and GetChildren()<\/h2>\n<p>In this section, we will get a JSON array using <code>IConfiguration<\/code> with the help of the <code>GetSection()<\/code> and <code>GetChildren()<\/code> methods. <code>GetSection()<\/code> retrieves a configuration sub-section with a specified key, and <code>GetChildren()<\/code> returns the immediate descendant configuration sub-sections. <strong>By using them together we can navigate hierarchically on any JSON structure<\/strong>.<\/p>\n<p>Let&#8217;s now see the model that we will use in this section:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public record User(int Id, string Name, string Role);<\/code><\/p>\n<p>Further, the first method that we will use in the API:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static IEnumerable&lt;User&gt; GetUsersArrayFromAppSettings(IConfiguration configuration)\r\n{\r\n    IConfigurationSection usersSection = configuration.GetSection(\"AppSettings:Users\");\r\n    IEnumerable&lt;IConfigurationSection&gt; usersArray = usersSection.GetChildren();\r\n    \r\n    return usersArray.Select(configSection =&gt; \r\n        new User \r\n        (\r\n            Id: int.Parse(configSection[\"Id\"]!.ToString()),\r\n            Name: configSection[\"Name\"]!.ToString(),\r\n            Role: configSection[\"Role\"]!.ToString())\r\n        );\r\n}<\/pre>\n<p>First, we use the method <code>GetSection()<\/code> which is returning an <code>IConfigurationSection<\/code>. <code>IConfigurationSection<\/code> represents a section of application configuration values and inherits from <code>IConfiguration<\/code>, so all methods available through <code>IConfiguration<\/code> we can use on <code>IConfigurationSection<\/code> as well. The <code>usersSection<\/code> is an array of users.<\/p>\n<p>Next, we use the <code>IConfiguration.GetChildren()<\/code> method to get each element in the array as a separate <code>IConfigurationSection<\/code>. The <code>GetChildren()<\/code> method returns <code>IEnumerable&lt;IConfigurationSection&gt;<\/code>. Each <code>IConfigurationSection<\/code> represents an item in the array <code>Users<\/code> in the appsettings.json.<\/p>\n<p>Finally, we extract the data from each <code>IConfigurationSection<\/code> element. We use the LINQ <code>Select()<\/code> method to project from <code>IConfigurationSection<\/code> to <code>User<\/code> object with the <code>Id<\/code>, <code>Name<\/code> and <code>Role<\/code> properties. Then, we use an indexer on the <code>configSection<\/code> to read the data. Because the indexer returns the data in a <code>string<\/code> type, for the <code>Id<\/code> property we parse it back to an <code>int<\/code>.<\/p>\n<h2>Get JSON Array Using Using IConfiguration With Get&lt;T&gt;()<\/h2>\n<p>It is often more convenient to map the JSON data to a C# type. Let&#8217;s create the necessary types to represent the JSON data:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"3-6\">public record User(int Id, string Name, string Role);\r\n\r\npublic record AppSettings\r\n{\r\n    public List&lt;User&gt;? Users { get; init; }\r\n};<\/pre>\n<p>Further, with the help of <code>IConfiguration.Get&lt;T&gt;()<\/code> method, we will get a JSON array, in a much more straightforward way:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static List&lt;User&gt;? GetUsersArrayFromAppSettingsV2(IConfiguration configuration)\r\n{\r\n    return configuration.GetSection(\"AppSettings:Users\").Get&lt;List&lt;User&gt;&gt;();\r\n}<\/pre>\n<p>We use the <code>GetSection()<\/code> method to get the <code>IConfigurationSection<\/code> with <code>AppSettings:Users<\/code> key. In the appsettings.json file, this is an array of users. Then, instead of going through each child, we use the <code>Get&lt;T&gt;()<\/code> method where <code>T<\/code> in our case is <code>List&lt;User&gt;<\/code>, and it attempts to bind it to the specified type.\u00a0<\/p>\n<h2>Get Nested JSON Array Using IConfiguration With Get&lt;T&gt;()<\/h2>\n<p>Finally, we will read nested JSON arrays using the <code>IConfiguration.Get&lt;T&gt;()<\/code> method. <strong>This method works by attempting to bind the configuration instance to a new instance of the provided type <code>T<\/code><\/strong>. If this configuration section has a value, that will be used. Otherwise, the binding is done by recursively matching property names against configuration keys.<\/p>\n<p>First, we will extend our model so that we can map the groups and members of each group from the appsettings.json file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"3,5-8,13\">public record User(int Id, string Name, string Role);\r\n\r\npublic record Member(int Id, string Name);\r\n\r\npublic record Group(int Id, string Name)\r\n{\r\n    public List&lt;Member&gt;? Members { get; init; }\r\n};\r\n\r\npublic record AppSettings\r\n{\r\n    public List&lt;User&gt;? Users { get; init; }\r\n    public List&lt;Group&gt;? Groups { get; init; }\r\n};<\/pre>\n<p>We add the <code>Member<\/code> and <code>Group<\/code> types, which are records. Then, we extend the <code>AppSettings<\/code> record with the <code>Groups<\/code> property.\u00a0<\/p>\n<p>Further, we will read the nested array <code>Members<\/code> under the <code>Group<\/code> record type:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static IEnumerable&lt;Member&gt;? GetGroupMembers(IConfiguration configuration)\r\n{\r\n    AppSettings? appSettings = configuration.GetSection(\"AppSettings\")?.Get&lt;AppSettings&gt;();\r\n    \r\n    return appSettings?.Groups?.SelectMany(x =&gt; x.Members);\r\n}<\/pre>\n<p>We use the <code>GetSection()<\/code> and the <code>Get&lt;T&gt;()<\/code> methods as in the previous example, with the only difference in the key, and the key is <code>AppSettings<\/code>. Then, we iterate through the <code>Groups<\/code> and with the help of <code>SelectMany()<\/code> and <code>Distinct()<\/code> methods, we return all distinct <code>Members<\/code> from each group.<\/p>\n<h2>Pitfalls of Using IConfiguration<\/h2>\n<p>When working with arrays using <code>IConfiguration<\/code> in ASP.NET Core, it&#8217;s essential to be aware of potential problems that can arise and know how to handle them effectively. In this section, we will explore some common challenges and provide solutions to deal with them.<\/p>\n<h3>Missing or Incorrect Configuration Section<\/h3>\n<p>One common issue is when the configuration section containing the array is missing or incorrectly specified. This can lead to errors or unexpected behavior when trying to retrieve the array from the configuration. <strong>To handle this, you can use conditional checks to verify the existence of the section before accessing it:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">if (configuration.GetSection(\"MyArraySection\").Exists())\r\n{\r\n    var myArray = configuration.GetSection(\"MyArraySection\").Get&lt;string[]&gt;();\r\n    \/\/ Process the array\r\n}\r\nelse\r\n{\r\n    \/\/ Handle the missing section scenario\r\n}\r\n<\/pre>\n<h3>Mismatch Between JSON Structure and C# Class Structure<\/h3>\n<p>Another challenge can arise when there is a mismatch between the structure of the JSON array in the configuration file and the corresponding C# class structure used for mapping. In such cases, the mapping may fail, resulting in null or default values. It&#8217;s crucial to ensure that the structure of the C# class matches the JSON structure accurately. <strong>Consider using tools like Newtonsoft.Json or System.Text.Json to deserialize the array into a strongly typed object<\/strong>. This allows for better validation and error handling during the mapping process.<\/p>\n<h3>Misinterpretation of Null Values<\/h3>\n<p>Handling null values in arrays can be tricky, especially when dealing with optional or nullable elements. By default, when deserializing an array, null values are ignored and not included in the resulting array. <strong>If you need to include null values, you can configure the deserialization behavior accordingly<\/strong>. For example, using Newtonsoft.Json, you can specify <code>NullValueHandling.Include<\/code> to ensure null values are preserved in the deserialized array.<\/p>\n<h3>Incorrect Data Type Mapping<\/h3>\n<p>It&#8217;s essential to ensure that the data types specified in the configuration match the expected types in your code. If there is a mismatch, the mapping process may throw an exception or provide unexpected results. <strong>Take care to validate the data types and handle any potential type conversion errors appropriately<\/strong>. You can use techniques like <code>TryParse()<\/code> to handle conversions and provide meaningful error messages when encountering incompatible data types.<\/p>\n<h3>Ignoring Case Sensitivity<\/h3>\n<p>In ASP.NET Core&#8217;s configuration system, keys are case-sensitive by default.<strong> This means that the configuration keys in the JSON file must match the keys used when accessing the configuration values<\/strong>. Be cautious about any differences in letter casing, as it can lead to configuration values not being found or retrieved correctly.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, we have explored different ways to get JSON arrays and nested JSON arrays using the IConfiguration interface in ASP.NET Core. We have demonstrated how to access the JSON data directly and how to map it to C# record types for more structured access and processing.<\/p>\n<p>We should mention at this point that using the <a href=\"https:\/\/code-maze.com\/aspnet-configuration-options\/\" target=\"_blank\" rel=\"noopener \u201cnooopener\u201d\">Options pattern<\/a> provided by ASP.NET Core is superior to this approach (due to type safety, ease of testing, sub-section mapping, etc.).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will explore how to get a JSON array using IConfiguration. In modern web applications, JSON is a widely used data interchange format due to its lightweight nature and ease of use. When developing an ASP.NET Core application, it is common to store configuration data, such as settings and connection strings, in [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62187,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1369],"tags":[1933,1120,79,1935,146,1934,1436,927,734],"class_list":["post-94916","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-json","tag-appsettings-json","tag-arrays","tag-asp-net-core","tag-asp-net-core-configuration","tag-configuration","tag-getsection","tag-iconfiguration","tag-json","tag-options-pattern","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Get a JSON Array Using IConfiguration in ASP.NET Core<\/title>\n<meta name=\"description\" content=\"In this article, we will explore how to get JSON array using IConfiguration with GetSection, GetChildren, and Get methods in ASP.NET Core\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Get a JSON Array Using IConfiguration in ASP.NET Core\" \/>\n<meta property=\"og:description\" content=\"In this article, we will explore how to get JSON array using IConfiguration with GetSection, GetChildren, and Get methods in ASP.NET Core\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-29T06:17:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-29T06:22:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Code Maze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"How to Get a JSON Array Using IConfiguration in ASP.NET Core\",\"datePublished\":\"2023-08-29T06:17:39+00:00\",\"dateModified\":\"2023-08-29T06:22:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/\"},\"wordCount\":1127,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"keywords\":[\"appsettings.json\",\"arrays\",\"asp.net core\",\"ASP.NET Core Configuration\",\"configuration\",\"GetSection\",\"IConfiguration\",\"JSON\",\"options pattern\"],\"articleSection\":[\"JSON\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/\",\"url\":\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/\",\"name\":\"How to Get a JSON Array Using IConfiguration in ASP.NET Core\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"datePublished\":\"2023-08-29T06:17:39+00:00\",\"dateModified\":\"2023-08-29T06:22:35+00:00\",\"description\":\"In this article, we will explore how to get JSON array using IConfiguration with GetSection, GetChildren, and Get methods in ASP.NET Core\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"width\":1100,\"height\":620,\"caption\":\"ASP.NET Core\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Get a JSON Array Using IConfiguration in ASP.NET Core\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Get a JSON Array Using IConfiguration in ASP.NET Core","description":"In this article, we will explore how to get JSON array using IConfiguration with GetSection, GetChildren, and Get methods in ASP.NET Core","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/","og_locale":"en_US","og_type":"article","og_title":"How to Get a JSON Array Using IConfiguration in ASP.NET Core","og_description":"In this article, we will explore how to get JSON array using IConfiguration with GetSection, GetChildren, and Get methods in ASP.NET Core","og_url":"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/","og_site_name":"Code Maze","article_published_time":"2023-08-29T06:17:39+00:00","article_modified_time":"2023-08-29T06:22:35+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"How to Get a JSON Array Using IConfiguration in ASP.NET Core","datePublished":"2023-08-29T06:17:39+00:00","dateModified":"2023-08-29T06:22:35+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/"},"wordCount":1127,"commentCount":1,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","keywords":["appsettings.json","arrays","asp.net core","ASP.NET Core Configuration","configuration","GetSection","IConfiguration","JSON","options pattern"],"articleSection":["JSON"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/","url":"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/","name":"How to Get a JSON Array Using IConfiguration in ASP.NET Core","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","datePublished":"2023-08-29T06:17:39+00:00","dateModified":"2023-08-29T06:22:35+00:00","description":"In this article, we will explore how to get JSON array using IConfiguration with GetSection, GetChildren, and Get methods in ASP.NET Core","breadcrumb":{"@id":"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","width":1100,"height":620,"caption":"ASP.NET Core"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/aspnetcore-get-json-array-using-iconfiguration\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"How to Get a JSON Array Using IConfiguration in ASP.NET Core"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/94916","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=94916"}],"version-history":[{"count":3,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/94916\/revisions"}],"predecessor-version":[{"id":95009,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/94916\/revisions\/95009"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62187"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=94916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=94916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=94916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}