borno
borno

Reputation: 31

How do I save a multiline string to a YAML file?

I have several YAML files that store SQL scripts in them (as multiline strings). I have a Python script that takes all of these scripts and aggregates them into a single table.

Whenever I make an update to a YAML file, it converts the SQL text to a regular string (with \n's to indicate line breaks). Is there a way to preserve the multiline formatting when I make updates to the YAML file?

Upvotes: 3

Views: 5768

Answers (1)

Narda Monserrat
Narda Monserrat

Reputation: 131

For multi-line scalars, you can use blocks. The pipe symbol character | to denote the start of a block.

For example:

Data: |
      Some data, here and a special character like ':'
      Another line of data on a separate line

Also you can check the YAML Multiline

Upvotes: 5

Related Questions