You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Test-Json cmdlet tests whether a string is a valid JavaScript Object Notation (JSON) document and can optionally very that JSON document against a provided schema.
24
23
25
-
The verified string can then be used with the ConvertFrom-Json cmdlet convert a JSON-formatted string to a JSON object, which is easily managed in PowerShell or sent to another program or web service that access JSON input.
24
+
The `Test-Json` cmdlet tests whether a string is a valid JavaScript Object Notation (JSON) document
25
+
and can optionally very that JSON document against a provided schema.
26
26
27
-
Many web sites use JSON instead of XML to serialize data for communication between servers and web-based apps.
27
+
The verified string can then be used with the `ConvertFrom-Json` cmdlet convert a JSON-formatted
28
+
string to a JSON object, which is easily managed in PowerShell or sent to another program or web
29
+
service that access JSON input.
28
30
29
-
This cmdlet was introduced in Windows PowerShell 6.1
31
+
Many web sites use JSON instead of XML to serialize data for communication between servers and
32
+
web-based apps.
33
+
34
+
This cmdlet was introduced in PowerShell 6.1
30
35
31
36
## EXAMPLES
32
37
33
38
### Example 1: Test if an object is valid JSON
39
+
40
+
This example tests whether the input string is a valid JSON document.
This Command takes a string containing a JSON schema and compares it to an input string. Since the input string conforms to the schema described in the -schema argument the cmdlet returns `$True`.
102
+
In this example, we get an error because the schema expects an integer for **age** but the JSON
103
+
input we tested uses a string value instead.
79
104
80
-
For more information, see [JSON Schema](https://json-schema.org/)
105
+
For more information, see [JSON Schema](https://json-schema.org/).
81
106
82
107
## PARAMETERS
83
108
84
109
### -Json
85
110
86
-
Specifies the JSON string to test for validity. Enter a variable that contains the string, or type a command or expression that gets the string. You can also pipe a string to `Test-Json`
111
+
Specifies the JSON string to test for validity. Enter a variable that contains the string, or type a
112
+
command or expression that gets the string. You can also pipe a string to `Test-Json`.
Specifies a Schema to validate the JSON input against. If passed `Test-Json` will validate that the Json input conforms to the spec specified by the `-Schema` parameter and return `$True` only if the input conforms to the provided Schema.
130
+
Specifies a Schema to validate the JSON input against. If passed `Test-Json` will validate that the
131
+
Json input conforms to the spec specified by the **Schema** parameter and return `$True` only if the
132
+
input conforms to the provided Schema.
105
133
106
-
For more information, see [JSON Schema](https://json-schema.org/)
134
+
For more information, see [JSON Schema](https://json-schema.org/).
107
135
108
136
```yaml
109
137
Type: String
@@ -135,11 +163,11 @@ You can pipe a JSON string to `Test-Json`.
135
163
136
164
## NOTES
137
165
138
-
The `Test-Json` cmdlet is implemented by using the [NJsonSchema Class](https://github.com/RSuter/NJsonSchema)
166
+
The `Test-Json` cmdlet is implemented by using the [NJsonSchema Class](https://github.com/RSuter/NJsonSchema).
139
167
140
168
## RELATED LINKS
141
169
142
-
[An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET](https://msdn.microsoft.com/en-us/library/bb299886.aspx)
170
+
[An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET](/previous-versions/dotnet/articles/bb299886(v=msdn.10))
The Test-Json cmdlet tests whether a string is a valid JavaScript Object Notation (JSON) document and can optionally very that JSON document against a provided schema.
24
23
25
-
The verified string can then be used with the ConvertFrom-Json cmdlet convert a JSON-formatted string to a JSON object, which is easily managed in PowerShell or sent to another program or web service that access JSON input.
24
+
The `Test-Json` cmdlet tests whether a string is a valid JavaScript Object Notation (JSON) document
25
+
and can optionally very that JSON document against a provided schema.
26
26
27
-
Many web sites use JSON instead of XML to serialize data for communication between servers and web-based apps.
27
+
The verified string can then be used with the `ConvertFrom-Json` cmdlet convert a JSON-formatted
28
+
string to a JSON object, which is easily managed in PowerShell or sent to another program or web
29
+
service that access JSON input.
28
30
29
-
This cmdlet was introduced in Windows PowerShell 6.1
31
+
Many web sites use JSON instead of XML to serialize data for communication between servers and
32
+
web-based apps.
33
+
34
+
This cmdlet was introduced in PowerShell 6.1
30
35
31
36
## EXAMPLES
32
37
33
38
### Example 1: Test if an object is valid JSON
39
+
40
+
This example tests whether the input string is a valid JSON document.
This Command takes a string containing a JSON schema and compares it to an input string. Since the input string conforms to the schema described in the -schema argument the cmdlet returns `$True`.
102
+
In this example, we get an error because the schema expects an integer for **age** but the JSON
103
+
input we tested uses a string value instead.
79
104
80
-
For more information, see [JSON Schema](https://json-schema.org/)
105
+
For more information, see [JSON Schema](https://json-schema.org/).
81
106
82
107
## PARAMETERS
83
108
84
109
### -Json
85
110
86
-
Specifies the JSON string to test for validity. Enter a variable that contains the string, or type a command or expression that gets the string. You can also pipe a string to `Test-Json`
111
+
Specifies the JSON string to test for validity. Enter a variable that contains the string, or type a
112
+
command or expression that gets the string. You can also pipe a string to `Test-Json`.
Specifies a Schema to validate the JSON input against. If passed `Test-Json` will validate that the Json input conforms to the spec specified by the `-Schema` parameter and return `$True` only if the input conforms to the provided Schema.
130
+
Specifies a Schema to validate the JSON input against. If passed `Test-Json` will validate that the
131
+
Json input conforms to the spec specified by the **Schema** parameter and return `$True` only if the
132
+
input conforms to the provided Schema.
105
133
106
-
For more information, see [JSON Schema](https://json-schema.org/)
134
+
For more information, see [JSON Schema](https://json-schema.org/).
107
135
108
136
```yaml
109
137
Type: String
@@ -135,11 +163,11 @@ You can pipe a JSON string to `Test-Json`.
135
163
136
164
## NOTES
137
165
138
-
The `Test-Json` cmdlet is implemented by using the [NJsonSchema Class](https://github.com/RSuter/NJsonSchema)
166
+
The `Test-Json` cmdlet is implemented by using the [NJsonSchema Class](https://github.com/RSuter/NJsonSchema).
139
167
140
168
## RELATED LINKS
141
169
142
-
[An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET](https://msdn.microsoft.com/en-us/library/bb299886.aspx)
170
+
[An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET](/previous-versions/dotnet/articles/bb299886(v=msdn.10))
0 commit comments