Update-OfficeYaml
Applies a JSON Patch (RFC 6902) or JSON Merge Patch (RFC 7386) to a live YAML document.
Syntax
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.
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.
Update-OfficeYaml -Document $document -JsonPatch (Get-Content ./scale.patch.json -Raw) -PassThruOverride values and remove a key with a merge patch.
Update-OfficeYaml -Document $document -MergePatch @{ image = @{ tag = '1.27.2' }; podAnnotations = $null }Parameters
- -Document YamlDocument
- Gets or sets an explicit live document; omission uses the enclosing content block.
- -JsonPatch Object
- The JSON Patch operations: JSON or YAML text, a YAML document, or an array of hashtables or objects.
- -PassThru SwitchParameter
- Return the report of added, replaced and removed paths.
- -MergePatch Object
- 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.