# Update-OfficeYaml

Applies a JSON Patch (RFC 6902) or JSON Merge Patch (RFC 7386) to a live YAML document.

Cmdlet 

**Module**

`PSWriteOffice`

**Inputs**

`OfficeIMO.Yaml.YamlDocument`

**Outputs**

`OfficeIMO.Yaml.YamlPatchReport`

**Source**

[UpdateOfficeYamlCommand.cs:28](https://github.com/EvotecIT/OfficeIMO/blob/b1c09e702e3f8960d25d38eeea728a1c0c8f2220/PowerShell/PSWriteOffice/Sources/PSWriteOffice/Cmdlets/Yaml/UpdateOfficeYamlCommand.cs#L28) 

Applies a JSON Patch (RFC 6902) or JSON Merge Patch (RFC 7386) to a live YAML document.

## Syntax

```
Update-OfficeYaml
[-Document <YamlDocument>]
[-JsonPatch] <Object>
[-PassThru]
[<CommonParameters>]
```

[#](#method-update-officeyaml-yamldocument-object-switchparameter)

Parameter set: `JsonPatch`

```
Update-OfficeYaml
[-Document <YamlDocument>]
-MergePatch <Object>
[-PassThru]
[<CommonParameters>]
```

[#](#method-update-officeyaml-yamldocument-object-switchparameter-2)

Parameter set: `MergePatch`

## Description

-JsonPatch takes a list of add, remove, replace, move, copy and test operations whose paths are JSON Pointers such as /spec/replicas. -MergePatch takes a partial document whose keys overwrite the document's, where $null removes a key. Either can be JSON or YAML text, a YAML document, or PowerShell hashtables, arrays and objects.

Only the patched lines change; comments, quoting and layout elsewhere stay. A patch is all or nothing: when a test fails, a path is missing or an edit cannot be made, a non-terminating yaml-patch-failed error is written and the document is unchanged. Patches address the first document of a multi-document stream.

## Examples

### Scale a deployment only if it still has the expected replica count.

```powershell
Open-OfficeYaml -Path ./deployment.yaml {
    Update-OfficeYaml -JsonPatch @(
        @{ op = 'test'; path = '/spec/replicas'; value = 2 }
        @{ op = 'replace'; path = '/spec/replicas'; value = 3 }
    )
}
```

### Apply a patch file and list what changed.

```powershell
Update-OfficeYaml -Document $document -JsonPatch (Get-Content ./scale.patch.json -Raw) -PassThru
```

### Override values and remove a key with a merge patch.

```powershell
Update-OfficeYaml -Document $document -MergePatch @{ image = @{ tag = '1.27.2' }; podAnnotations = $null }
```

## Parameters

**-Document YamlDocument optionalpipeline: True (ByValue)**

Gets or sets an explicit live document; omission uses the enclosing content block.

**-JsonPatch Object requiredposition: 0sets: JsonPatch**

The JSON Patch operations: JSON or YAML text, a YAML document, or an array of hashtables or objects.

**-PassThru SwitchParameter optional**

Return the report of added, replaced and removed paths.

**-MergePatch Object requiredsets: MergePatch**

The merge patch: JSON or YAML text, a YAML document, or a hashtable or object; $null values remove keys.

## Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see [about_CommonParameters](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters).

<!-- PowerForge markdown artifact sha256:029D0A388B57E3A984603801B1C5C60988659777F24EDF1DF4F1EFBBE9620759 -->
