From 066dade82f319d0006414f71306ed743befe3faf Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Wed, 18 Dec 2024 18:41:41 +0200 Subject: [PATCH] Update README.md Add examples of serializing to Flow style. Signed-off-by: Gabriel Adrian Samfira --- README.md | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/README.md b/README.md index 760b26e..501d1e2 100644 --- a/README.md +++ b/README.md @@ -243,6 +243,71 @@ True True Int64 System.ValueType As you can see, the phone number without tags was cast to ```Int64```. This is most likely not the desired result and a case where tags should be used. +## Controlling output formatting + +By default `ConvertTo-Yaml` will output in `Block` style. You can control the output formatting by using `-Options` parameter and specifying one of the following values: `UseFlowStyle` or `UseSequenceFlowStyle`. The `UseFlowStyle` option will output everything in `Flow` style. The `UseSequenceFlowStyle` option will output sequences in `Flow` style and everything else in `Block` style. + +Here is an example of using the `UseFlowStyle` option: + +```powershell +Import-Module powershell-yaml + +PS C:\> $data = @{ + "anArray" = @(1, 2, 3) + "nested" = @{ + "array" = @("this", "is", "an", "array") + } + "hello" = "world" +} + +PS C:\> ConvertTo-Yaml $data -Options UseFlowStyle +{anArray: [1, 2, 3], nested: {array: [this, is, an, array]}, hello: world} +``` + +Here is an example of using the `UseSequenceFlowStyle` option: + +```powershell +PS C:\> ConvertTo-Yaml $data -Options UseSequenceFlowStyle + +anArray: [1, 2, 3] +nested: + array: [this, is, an, array] +hello: world +``` + +There is another tweak you can use. When using the default `Block` style, sequences are not indented. You can toggle this by passing in the `WithIndentedSequences` option. + +Here are examples with and without indented sequences: + +```powershell +PS C:\> ConvertTo-Yaml $data +anArray: +- 1 +- 2 +- 3 +nested: + array: + - this + - is + - an + - array +hello: world + + +PS C:\> ConvertTo-Yaml $data -Options WithIndentedSequences +anArray: + - 1 + - 2 + - 3 +nested: + array: + - this + - is + - an + - array +hello: world +``` + ## Running the tests Before running the associated unit tests; please make sure you have