Data workflow guides

Convert INI Sections to YAML Strings

·

When moving an INI file to YAML, first decide which settings carry text even when they look like numbers. Confirm how the destination expects named sections and global keys to be organized.

INI to YAML

Find the warehouse keys in the YAML output

Select Load example and Convert to YAML. Profile is a top-level key with the value live. The warehouse.eu and warehouse.us sections become separate mappings. The period in each section name stays part of its key.

Under warehouse.eu, ShelfCode contains the four characters 0012, Enabled holds the string false, and Empty holds the empty string. Under warehouse.us, ShelfCode keeps all the digits in 90071992547409930001.

Python configparser, a sectioned INI dialect for comparisonYAML 1.2.2, core schema and scalar types

Check which punctuation belongs to the value

This converter uses a line-based INI dialect. An equals sign or colon separates each key from its value. Surrounding whitespace is removed. An entire line beginning with # or a semicolon is a comment. In the Memo value, both the semicolon and the hash remain after conversion.

The quotation marks in the Label value are literal characters, so its YAML string includes them and the spaces inside them. Remove those quotation marks in the source and convert again if you want the characters Keep me without the padding. Interpolation, multiline values and inherited sections are outside this dialect.

Python configparser, a sectioned INI dialect for comparisonYAML 1.2.2, core schema and scalar types

Reopen the YAML and check its key paths

Download and open the YAML in a parser. Check that warehouse.eu contains ShelfCode and that its value is a string. If your application expects warehouse and eu as separate levels, edit the nesting in the YAML and verify it against the destination’s schema.

If the converter reports a duplicate, compare the two line numbers. Keep the assignment your application should use. A section name that matches a top-level key must be renamed before both can appear in the YAML mapping.

Python configparser, a sectioned INI dialect for comparisonYAML 1.2.2, core schema and scalar types

Common questions

Can I repeat the same key across sections?

Yes. Each section has its own mapping. Repeating a key in the same section reports a duplicate.

Will [1, true] turn into a YAML sequence?

The complete text [1, true] stays one string when used as an INI value. Convert it to a sequence separately if the destination requires one.

Sources

Put it into practice.

Related guides