Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Update-OfficeToml

Module
PSWriteOffice
Inputs
OfficeIMO.Toml.TomlDocument
Outputs
OfficeIMO.Toml.TomlPatchReport

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

Syntax

Update-OfficeToml
[-Document <TomlDocument>]
[-JsonPatch] <Object>
[-PassThru]
[<CommonParameters>]
#
Parameter set: JsonPatch
Update-OfficeToml
[-Document <TomlDocument>]
-MergePatch <Object>
[-PassThru]
[<CommonParameters>]
#
Parameter set: MergePatch

Description

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

Only the patched lines change; comments and layout elsewhere stay. New objects become [header] tables and arrays of objects [[header]] arrays of tables. TOML has no null, so a null value in a JSON Patch fails. A patch is all or nothing: when a test fails, a path is missing or an edit cannot be made, a non-terminating toml-patch-failed error is written and the document is unchanged.

Examples

Bump a version only if it is the expected one.

Open-OfficeToml -Path ./pyproject.toml {
    Update-OfficeToml -JsonPatch @(
        @{ op = 'test'; path = '/project/version'; value = '1.4.0' }
        @{ op = 'replace'; path = '/project/version'; value = '1.5.0' }
        @{ op = 'add'; path = '/project/dependencies/-'; value = 'click' }
    )
}

Change a setting and remove another with a merge patch.

Update-OfficeToml -Document $document -MergePatch @{ tool = @{ ruff = @{ 'line-length' = 100; exclude = $null } } } -PassThru

Parameters

-Document TomlDocument 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 text, 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 text, 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.