Add Property parameter to Test-Json
See original GitHub issueSummary of the new feature / enhancement
On the back of #12272 in which since that was raised both Path
and SchemaPath
parameters have been added this request is to add a Property
parameter that accepts a string array of properties to test for.
This is so that
Test-Json -Path .\test.json -SchemaPath .\schema.json -Property Time,Date,Location
would perhaps return True if all 3 exist False if all 3 do not exist An object that that shows which exist and which do not exist that can be easily passed to any other downstream cmdlet or application
Proposed technical implementation details (optional)
No response
Issue Analytics
- State:
- Created 3 months ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
How to add property in existing json using System.Text. ...
In the above sample JSON I want to add a property called "Name" with Value "John" inside property "TestData". How can I achieve...
Read more >Test-Json (Microsoft.PowerShell.Utility)
The SchemaFile parameter accepts literal path to the JSON schema file and allows JSON files to be validated against such schemas. In this...
Read more >How to Test JSON Properties in Postman
In this blog post, we'll walk through an overview of JSON architecture, structure, and its examples. Then, we'll check out some code snippets ......
Read more >InputPath, Parameters and ResultSelector
Use the Parameters field to create a collection of key-value pairs that are passed as input. The values of each can either be...
Read more >Documentation - Object Types
Each property in an object type can specify a couple of things: the type, whether the property is optional, and whether the property...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If you only want to validate a subset of properties, you need to create a new schema that only contains those properties. Partial schema validation isn’t something that’s supported (by JSON Schema, not just this cmdlet).
For example, given the schema
This will validate all four properties, always. There’s no way to perform a partial validation by ignoring
Foo
.If you want to only validate
Time
,Date
, andLocation
, then you’ll need to create a new schema that validates just those.If you still need a schema that validates the entire thing, you can reference this new one in the other:
This new schema will validate everything in
my-selective-model
with the addition of theFoo
property.You’re welcome to perform a survey of the implementations, but I doubt you’ll find one that supports partial validation specifically because it’s not a feature of JSON Schema. Implementations tend to stick as closely to the spec as their language allows.
You’re also welcome to raise a proposal, but I can say with some confidence (because I’m one of the authors) that it probably won’t be. We aim to honor the intent of the schema author. If the schema author has elected to include/require properties, then that’s what needs to be validated. If something else needs to be validated, a different schema needs to be used.