Test-Json string format not matching
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Let’s create a very simple json schema that use the string format duration
:
{
"type": "object",
"additionalProperties":false,
"properties": {
"duration": {
"type": "string",
"format": "duration"
}
}
}
the format duration
was added in the json schema “draft 2019-09” current version is “draft 2020-12”. The goal of the duration
format is to match ISO 8601 (see: json schema documentation )
and save it in a file named schema.json
and run the following command to test:
> Test-Json -SchemaFile .\schema.json -Json '{"duration":"test123"}'
or
> Test-Json -SchemaFile .\schema.json -Json '{"duration":"PT1D"}'
the result will be True
when expecting False
Expected behavior
PS> Test-Json -SchemaFile .\schema.json -Json '{"duration":"test123"}'
False
PS> Test-Json -SchemaFile .\schema.json -Json '{"duration":"PT1D"}'
False
PS> Test-Json -SchemaFile .\schema.json -Json '{"duration":"P1D"}'
True
Actual behavior
PS> Test-Json -SchemaFile .\schema.json -Json '{"duration":"test123"}'
True
PS> Test-Json -SchemaFile .\schema.json -Json '{"duration":"PT1D"}'
True
PS> Test-Json -SchemaFile .\schema.json -Json '{"duration":"P1D"}'
True
Error details
No response
Environment data
Name Value
---- -----
PSVersion 7.4.0-preview.4
PSEdition Core
GitCommitId 7.4.0-preview.4
OS Microsoft Windows 10.0.22621
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
Issue Analytics
- State:
- Created 3 months ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
How to test if a string is JSON or not?
I think something like following method should do the job, it returns the parsed JSON (in case of valid JSON), so you don't...
Read more >Check Whether a String Is Valid JSON in Java
The most lightweight and simple library is the JSON API. The common approach for checking if a String is a valid JSON is...
Read more >How to Validate Your JSON Using JSON Schema
JSON Schema is a powerful tool. It enables you to validate your JSON structure and make sure it meets the required API. You...
Read more >JSON Online Validator and Formatter - JSON Lint
JSONLint is the free online validator, json formatter, and json beautifier tool for JSON, a lightweight data-interchange format. You can format json, ...
Read more >Validate JSON data using Python
In this article, we will see how to validate JSON data using Python. ... Here we are validating the Python dictionary in a...
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
In JSON Schema,
format
is an annotation by default. That means it doesn’t validate. So the current behavior is actually more correct, per the spec.The two solutions I see here are:
format
by default. This may align with expected behavior, but you wouldn’t be able to turn it off.-ValidateFormat
.The fix is pretty easy; we just need to decide which to do.
@gregsdennis Thanks! I hope WG will do a conclusion. /cc @SteveL-MSFT