< Back

ConvertTo-NewtonsoftJson

Mon Jan 13, 2020 7:29 pm

NAME ConvertTo-NewtonsoftJson



SYNOPSIS

Converts the PsObject, Array, or Hashtable into a json string.





SYNTAX

ConvertTo-NewtonsoftJson [-InputObject] <Object> [[-Settings] <JsonSerializerSettings>] [<CommonParameters>]





DESCRIPTION

An alternate ConvertTo-Json method that outputs readable json unlike

the native version for Powershell 5 and below.





PARAMETERS

-InputObject <Object>

The Array, PsObject, or Hashtable object that should be serialized to json



Required? true

Position? 1

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters? false



-Settings <JsonSerializerSettings>

(Optional) The Newtonsoft.Json.JsonSerializerSettings object that will be used

to serialized the Input Object.



Required? false

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>$jsonText = @("One", "Two") | ConvertTo-NewtonsoftJson













-------------------------- EXAMPLE 2 --------------------------



PS C:\\>$settings = New-NewtonsoftJsonSettings



PS C:\\>$camelCaseResolver = "Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver"

PS C:\\>$settings.ContractResolver = New-Object $camelCaseResolver

PS C:\\>$jsonText = @("One", "Two") | ConvertTo-NewtonsoftJson -Settings $settings











RELATED LINKS