Data workflow guides

Convert Java Properties to YAML Strings

·

A Java properties file can use backslashes to continue a value, embed a space in a key or store a character as a Unicode escape. Interpret those rules before moving the settings into YAML.

Java Properties to YAML

Follow the service name across two lines

Select Load example and Convert to YAML. The escaped space in the source key produces service name. Its value is NorthDock. The final backslash on the first line drops that line ending, and indentation before Dock is discarded. Add a space before the continuation backslash and convert again to read North Dock.

The greeting decodes to Grüße, the path contains a single backslash at each separator, and port is the string 00443. The source key optional has no value and becomes an empty string.

Java Properties API, Reader and InputStream syntaxYAML 1.2.2, double-quoted scalars

Read a file saved for Java InputStream

Save the Latin-1 inventory sample. Open it under the default Unicode setting to see the UTF-8 decoding error, then choose ISO-8859-1 (Java InputStream). The same file is read again. Convert and check that name is Café, status is prêt and code stays 0012.

Choose the file’s actual encoding rather than the encoding of an editor that displays it. The ISO-8859-1 setting interprets each byte as its matching character. Pasted text is already decoded.

ToolMellow Java inventory sample saved in ISO-8859-1Java Properties API, Reader and InputStream syntax

Verify exact strings in the new YAML mapping

Download the YAML and load it in your destination. Check that port still contains both leading zeros, that optional is empty and that the quotation marks around live remain in the label value. Java Properties treats those quotation marks as part of the value.

If a duplicate diagnostic appears, find the first and later assignments. Different spellings can decode to the same key. Select one entry before exporting. Dotted keys stay whole, so add nesting only where the destination schema requires it.

Java Properties API, Reader and InputStream syntaxYAML 1.2.2, double-quoted scalars

Common questions

Will an unrecognized escape cause an error?

Java Properties drops the backslash before an unrecognized escaped character. A Unicode escape beginning with a single u must have exactly four hexadecimal digits.

Which property separators are recognized?

An unescaped equals sign, colon, space, tab or form feed can end the key. Escape an actual separator character in the key with a backslash.

Sources

Put it into practice.

Related guides