Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
function ConvertTo-JsonManifest {
<#
.SYNOPSIS
Converts a Plaster XML manifest to JSON format.

.DESCRIPTION
Converts an XML-format Plaster manifest (plasterManifest.xml) to the JSON format
(plasterManifest.json) used by Plaster 2.0. Accepts an XmlDocument from
Test-PlasterManifest via the pipeline or the -XmlManifest parameter and returns
the resulting JSON as a string.

.PARAMETER XmlManifest
The parsed XML manifest to convert. Use Test-PlasterManifest to load and validate
a plasterManifest.xml file before passing it to this function.

.PARAMETER Compress
Omits white space and indented formatting in the output JSON string.

.EXAMPLE
$xml = Test-PlasterManifest -Path .\plasterManifest.xml
ConvertTo-JsonManifest -XmlManifest $xml | Set-Content .\plasterManifest.json

Converts plasterManifest.xml and writes the result to plasterManifest.json.

.EXAMPLE
Test-PlasterManifest -Path .\plasterManifest.xml | ConvertTo-JsonManifest | Set-Content .\plasterManifest.json

Pipes the validated manifest directly into ConvertTo-JsonManifest.

.INPUTS
System.Xml.XmlDocument

.OUTPUTS
System.String

.LINK
Test-PlasterManifest
#>
[CmdletBinding()]
[OutputType([string])]
param(
Expand Down Expand Up @@ -127,12 +164,11 @@ function ConvertTo-JsonManifest {

# Convert to JSON
$jsonParams = @{
InputObject = $jsonObject
Depth = 10
}

if (-not $Compress) {
$jsonParams['Compress'] = $false
if ($Compress) {
$jsonParams['Compress'] = $true
}

$jsonResult = $jsonObject | ConvertTo-Json @jsonParams
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ Define what the template does:

### Converting XML to JSON
```powershell
# Automatic conversion
# Convert an XML manifest to JSON
$xmlManifest = Test-PlasterManifest -Path .\plasterManifest.xml
ConvertTo-JsonManifest -InputObject $xmlManifest -OutputPath .\plasterManifest.json
ConvertTo-JsonManifest -XmlManifest $xmlManifest | Set-Content .\plasterManifest.json
# Or use New-PlasterManifest with conversion
New-PlasterManifest -TemplateName MyTemplate -TemplateType Project -ConvertFromXml
# Or pipe directly
Test-PlasterManifest -Path .\plasterManifest.xml | ConvertTo-JsonManifest | Set-Content .\plasterManifest.json
```

### Variable Syntax Updates
Expand Down
108 changes: 108 additions & 0 deletions docs/en-US/ConvertTo-JsonManifest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
external help file: Plaster-help.xml
Module Name: Plaster
online version: https://github.com/PowerShellOrg/Plaster/blob/master/docs/en-US/ConvertTo-JsonManifest.md
schema: 2.0.0
---

# ConvertTo-JsonManifest

## SYNOPSIS
Converts a Plaster XML manifest to JSON format.

## SYNTAX

```
ConvertTo-JsonManifest [-XmlManifest] <XmlDocument> [-Compress] [-ProgressAction <ActionPreference>]
[<CommonParameters>]
```

## DESCRIPTION
Converts an XML-format Plaster manifest (plasterManifest.xml) to the JSON format
(plasterManifest.json) used by Plaster 2.0. Accepts an XmlDocument from
Test-PlasterManifest via the pipeline or the -XmlManifest parameter and returns
the resulting JSON as a string.

## EXAMPLES

### Example 1
```powershell
$xml = Test-PlasterManifest -Path .\plasterManifest.xml
ConvertTo-JsonManifest -XmlManifest $xml | Set-Content .\plasterManifest.json
```

Converts plasterManifest.xml and writes the result to plasterManifest.json.

### Example 2
```powershell
Test-PlasterManifest -Path .\plasterManifest.xml | ConvertTo-JsonManifest | Set-Content .\plasterManifest.json
```

Pipes the validated manifest directly into ConvertTo-JsonManifest.

## PARAMETERS

### -Compress
Omits white space and indented formatting in the output JSON string.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -XmlManifest
The parsed XML manifest to convert. Use Test-PlasterManifest to load and validate
a plasterManifest.xml file before passing it to this function.

```yaml
Type: XmlDocument
Parameter Sets: (All)
Aliases:

Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -ProgressAction
{{ Fill ProgressAction Description }}

```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### System.Xml.XmlDocument
The validated XML manifest returned by Test-PlasterManifest.

## OUTPUTS

### System.String
A JSON string representation of the Plaster manifest.

## NOTES

## RELATED LINKS

[Test-PlasterManifest](https://github.com/PowerShellOrg/Plaster/blob/master/docs/en-US/Test-PlasterManifest.md)
2 changes: 1 addition & 1 deletion examples/TemplateModule/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Plaster 2.0 includes automatic conversion capabilities:
$xmlPath = ".\plasterManifest.xml"
$jsonPath = ".\plasterManifest.json"
$manifest = Test-PlasterManifest -Path $xmlPath
ConvertTo-JsonManifest -InputObject $manifest -OutputPath $jsonPath
ConvertTo-JsonManifest -XmlManifest $manifest | Set-Content $jsonPath
```

## Template Discovery
Expand Down
Loading
Loading