Convert Nested INI Sections with Dot Notation to Deep JSON
Handle INI files that use dot notation in section names (e.g., [section.subsection]) to create deeply nested JSON object hierarchies.
Detailed Explanation
Dot Notation for Deep Nesting
Some INI files use dot notation in section names to represent hierarchical configuration. For example, [database.primary] and [database.replica] both create objects nested under a database parent.
Example INI
[app]
name=MultiDB Service
version=3.0
[database.primary]
host=db-primary.example.com
port=5432
ssl=true
[database.replica]
host=db-replica.example.com
port=5432
ssl=true
readonly=true
[database.pool]
min=5
max=20
idle_timeout=30000
Generated JSON
{
"app": {
"name": "MultiDB Service",
"version": 3
},
"database": {
"primary": {
"host": "db-primary.example.com",
"port": 5432,
"ssl": true
},
"replica": {
"host": "db-replica.example.com",
"port": 5432,
"ssl": true,
"readonly": true
},
"pool": {
"min": 5,
"max": 20,
"idle_timeout": 30000
}
}
}
How Deep Nesting Works
The converter splits section names on dots and creates nested objects for each segment:
[a]→{ "a": { ... } }[a.b]→{ "a": { "b": { ... } } }[a.b.c]→{ "a": { "b": { "c": { ... } } } }
If a parent section (e.g., [database]) is not explicitly declared, the converter still creates the parent object to hold its children. Multiple subsections under the same parent are merged into the same parent object.
Round-Trip Conversion
When converting this JSON back to INI, the converter reconstructs the dot-notation section names, maintaining the original hierarchical structure.
Use Case
Working with complex application configurations that organize settings hierarchically, such as database connection pools with primary/replica/pool subsections, or logging configurations with separate handler settings.