# Settings nodes

Settings nodes are the intermediate representation of configuration data and one of the core concepts of the library. Their main purpose is to abstract away various configuration formats (JSON, XML, etc.) so that [binding to model classes](https://vostok.gitbook.io/configuration/concepts-and-basics/binding-nodes-to-models) can be implemented once without regard to the nature of [configuration sources](https://vostok.gitbook.io/configuration/concepts-and-basics/configuration-sources) being used.

### Key points

* A settings node is a tree with string keys and string values in its leaf nodes.
* [Configuration sources](https://vostok.gitbook.io/configuration/concepts-and-basics/configuration-sources) produce settings nodes as their primary artifacts.
* [Binding](https://vostok.gitbook.io/configuration/concepts-and-basics/binding-nodes-to-models) is the process of converting a settings node to an arbitrary .NET object.
* Settings nodes are implemented in the [abstractions module](https://vostok.gitbook.io/configuration/modules/abstractions).
* Settings nodes are immutable objects.

### Why is it necessary to learn about settings nodes?

Despite being a somewhat internal API used directly only in a handful of advanced scenarios, settings nodes are crucial for a solid understanding of how configuration data [translates](https://vostok.gitbook.io/configuration/concepts-and-basics/binding-nodes-to-models) to objects in C# code via different node types and [scoping](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes-scoping).

### When is there a need to use settings nodes directly?

* Implementation of a [custom configuration source](https://vostok.gitbook.io/configuration/advanced-scenarios/create-custom-sources);
* Implementation of a [custom model binder](https://vostok.gitbook.io/configuration/advanced-scenarios/apply-custom-binders);
* [Transformation](https://vostok.gitbook.io/configuration/advanced-scenarios/transform-sources) of configuration sources

### Node types

There are three types of nodes:

* [Value nodes](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes/value-nodes), used to hold data;
* [Array nodes](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes/array-nodes), used to represent sequences;
* [Object nodes](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes/object-nodes), used to represent objects with named properties.

Users are not expected to implement custom node types.

`Null` node instances represent absence of settings (e.g. a configuration file that does not exist).

### Node interface

All node types implement the [ISettingsNode](https://github.com/vostok/configuration.abstractions/blob/master/Vostok.Configuration.Abstractions/SettingsTree/ISettingsNode.cs) interface and have following properties:

| Property     | Type                         | Description                                                                                                                                                                                                                                     |
| ------------ | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Name`       | `string`                     | Node name. Case-insensitive.                                                                                                                                                                                                                    |
| `Value`      | `string`                     | Node value. Only present in [value nodes](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes/value-nodes).                                                                                                              |
| `Children`   | `IEnumerable<ISettingsNode>` | Sequence of child nodes in containers: [arrays](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes/array-nodes) and [objects](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes/object-nodes). |
| `this[name]` | `ISettingsNode`              | Name-based indexer used to navigate [objects](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes/object-nodes) (see [scoping](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes-scoping)).     |

All nodes also implement a [merge](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes-merging) operation.

### Representation

All node types implement a JSON-like `ToString()` method. Its result may look like this for a sample [object node](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes/object-nodes) with two nested [value nodes](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes/value-nodes):

```
{
   "A": "1",
   "B": "2"
}
```

This representation is extensively used on the rest of the pages.&#x20;

### Related pages

{% content-ref url="settings-nodes/value-nodes" %}
[value-nodes](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes/value-nodes)
{% endcontent-ref %}

{% content-ref url="settings-nodes/array-nodes" %}
[array-nodes](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes/array-nodes)
{% endcontent-ref %}

{% content-ref url="settings-nodes/object-nodes" %}
[object-nodes](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes/object-nodes)
{% endcontent-ref %}

{% content-ref url="settings-nodes-merging" %}
[settings-nodes-merging](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes-merging)
{% endcontent-ref %}

{% content-ref url="settings-nodes-scoping" %}
[settings-nodes-scoping](https://vostok.gitbook.io/configuration/concepts-and-basics/settings-nodes-scoping)
{% endcontent-ref %}

{% content-ref url="configuration-sources" %}
[configuration-sources](https://vostok.gitbook.io/configuration/concepts-and-basics/configuration-sources)
{% endcontent-ref %}

{% content-ref url="binding-nodes-to-models" %}
[binding-nodes-to-models](https://vostok.gitbook.io/configuration/concepts-and-basics/binding-nodes-to-models)
{% endcontent-ref %}
