# Update-OfficeToml

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

Cmdlet 

**Module**

`PSWriteOffice`

**Inputs**

`OfficeIMO.Toml.TomlDocument`

**Outputs**

`OfficeIMO.Toml.TomlPatchReport`

**Source**

[UpdateOfficeTomlCommand.cs:29](https://github.com/EvotecIT/OfficeIMO/blob/b1c09e702e3f8960d25d38eeea728a1c0c8f2220/PowerShell/PSWriteOffice/Sources/PSWriteOffice/Cmdlets/Toml/UpdateOfficeTomlCommand.cs#L29) 

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>]
```

[#](#method-update-officetoml-tomldocument-object-switchparameter)

Parameter set: `JsonPatch`

```
Update-OfficeToml
[-Document <TomlDocument>]
-MergePatch <Object>
[-PassThru]
[<CommonParameters>]
```

[#](#method-update-officetoml-tomldocument-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 /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.

```powershell
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.

```powershell
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](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters).

<!-- PowerForge markdown artifact sha256:6E9FFB399516B83B76E1B84789399FDAACD6CDD29E0521F84265F0ECB66556A1 -->
