external help file | Module Name | online version | schema |
---|---|---|---|
schema-help.xml |
schema |
2.0.0 |
This function takes the output of ConvertFrom-Json CmdLet and converts it into SchemaModule classes.
ConvertTo-SchemaElement [-Object] <Object> [-IsRootSchema] [<CommonParameters>]
This function takes the output of ConvertFrom-Json CmdLet and converts it into SchemaModule classes. The input to ConvertFrom-Json should be a proper JSON schema file, or a file with proper JSON schema objects. It will then convert those into one of the defined classes schemaDocument, schemaObject, schemaArray, schemaString, schemaInteger, schemaNumber or schemaBoolean.
PS C:\> $Schema = Get-SchemaDocument -Path 'D:\TEMP\test\schema-sample.json'
ConvertTo-SchemaElement -Object $Schema.properties.room
$id : #/properties/room
title : The room schema
description : An explanation about the purpose of this instance.
default :
This example shows how to use the function to convert an object into a schema class.
PS C:\> $Schema = Get-SchemaDocument -Path 'D:\TEMP\test\schema-sample.json'
ConvertTo-SchemaElement -Object $Schema.properties.room |fl *
type : string
id : #/properties/room
ref :
minLength : 0
maxLength : 0
pattern :
enum :
title : The room schema
description : An explanation about the purpose of this instance.
default :
examples : {}
To see the full list of properties on a class simply add an asterisk to the Format-List CmdLet.
This switch allows the function to know when it's working with the root of a schema document versus a regular object.
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
This is a JSON Schema object as defined by the json-schema.org (see related links below). This object is then converted into a PowerShell object that can be used like any other PowerShell object.
{ "type": "string", "examples": [
], "id": "#/properties/room", "ref": null, "minLength": 0, "maxLength": 0, "pattern": null, "enum": null, "title": "The room schema", "description": "An explanation about the purpose of this instance.", "default": "" }
Type: System.Object
Parameter Sets: (All)
Aliases:
Required: True
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
This class is really modified object that contains the $schema attribute as well as validation on what values can be present for that attribute. Schema Object (https://json-schema.org/understanding-json-schema/reference/object.html) Schema Keyword (https://json-schema.org/understanding-json-schema/reference/schema.html) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)
The string type is used for strings of text. It may contain Unicode characters. Schema String (https://json-schema.org/understanding-json-schema/reference/string.html) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)
The integer type is used for integral numbers. In PowerShell this is an int32 Schema Integer (http://json-schema.org/understanding-json-schema/reference/numeric.html#integer) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)
The number type is used for any numeric type, either integers or floating point numbers. In PowerShell this is a double. Schema Number (http://json-schema.org/understanding-json-schema/reference/numeric.html#number) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)
The boolean type matches only two special values: true and false. Note that values that evaluate to true or false, such as 1 and 0, are not accepted by the schema. Schema Boolean (http://json-schema.org/understanding-json-schema/reference/boolean.html) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)
Objects are the mapping type in JSON. They map "keys" to "values". In JSON, the "keys" must always be strings. Each of these pairs is conventionally referred to as a "property". Schema Object (https://json-schema.org/understanding-json-schema/reference/object.html) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)
Arrays are used for ordered elements. In JSON, each element in an array may be of a different type. Schema Array (https://json-schema.org/understanding-json-schema/reference/array.html) Schema Types (https://json-schema.org/understanding-json-schema/reference/type.html)