Skip to content

Powershell module

Rob Green edited this page Apr 22, 2023 · 2 revisions

PsJsonToPowershellClass

PowerShell Gallery Version PowerShell Gallery

A Powershell module that converts JSON to Powershell classes. JSON can be supplied as a string, a file that will be read or a URL that will be downloaded.

Available in the Powershell Gallery

Description

Convert JSON to Powershell classes. JSON can be supplied as a string, a file that will be read or a URL that will be downloaded.

Optionally create functions showing example usage.

Optionally write an output file.

Optionally copy the output to clipboard.

Installation (from the Powershell Gallery)

Install-Module  JsonToPowershellClass
Import-Module  JsonToPowershellClass

Included cmdlets

Convert-JsonToPowershellClass

Examples

Convert a JSON file to Powershell classes including usage examples and copy the output to clipboard.

Convert-JsonToPowershellClass -JsonFile 'C:\Temp\a-json-file.json' -CopyToClipboard -IncludeExamples

Download JSON from a URL, convert to Powershell classes using 'TestyMcTestFace' as the root class, include usage examples, copy to clipboard and write a ps1 file to the file system

Convert-JsonToPowershellClass -Url 'https://dummyjson.com/products' -IncludeExamples -CopyToClipboard -OutputFile 'C:\Users\rob\Downloads\sample_new3.ps1' -RootObjectClassName TestyMcTestyFace

Building the module and importing locally

Build the .NET core solution

dotnet build [Github clone/download directory]\ps-json-to-powershell-class\src\PsJsonToPowershellClass\PsJsonToPowershellClass.csproj

Copy the built files to your Powershell modules directory

Remove any existing installation in this directory, create a new module directory and copy all the built files.

Remove-Item "C:\Users\[User]\Documents\PowerShell\Modules\JsonToPowershellClass" -Recurse -Force -ErrorAction SilentlyContinue
New-Item -Path 'C:\Users\[User]\Documents\PowerShell\Modules\JsonToPowershellClass' -ItemType Directory
Get-ChildItem -Path "[Github clone/download directory]\ps-json-to-powershell-class\src\PsJsonToPowershellClass\bin\Debug\net6.0\" | Copy-Item -Destination "C:\Users\[User]\Documents\PowerShell\Modules\JsonToPowershellClass" -Recurse