ConvertFrom-Json and Test-Json accept non-compliant/non-standard JSON - no way to strictly validate JSON
See original GitHub issueSummary of the new feature/enhancement
There does not seem to be any way to validate whether a JSON string is valid, which makes it impossible to use PowerShell to validate JSON before passing it to another application.
For example, the following JSON is invalid due to the trailing comma, but Test-Json
still returns $true
.
'{"hello": "world",}' | Test-Json
I propose adding a -Strict
parameter to Test-Json
for testing that the JSON string adheres strictly to the JSON specification.
Side note
I was very excited when I found the Test-Json
cmdlet, but so far every use case it would have helped, it has not behaved as expected. See also #9560. If this cannot be implemented using the current library, please strongly consider using Json.NET instead of NJsonSchema.
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (2 by maintainers)
Top Results From Across the Web
no way to strictly validate JSON
ConvertFrom-Json and Test-Json accept non-compliant/non-standard JSON - no way to strictly validate JSON #12046. Sign in to view logs · Sign in to...
Read more >Test-Json (Microsoft.PowerShell.Utility)
The Test-Json cmdlet tests whether a string is a valid JavaScript Object Notation (JSON) document and can optionally verify that JSON document against...
Read more >Validate if string is valid json (fastest way possible) in .NET ...
I know i can use an external library(newtonsoft) with a try/catch to check if a string is valid json structure. I do not...
Read more >Three Ways to Validate JSON in Java | by Guillaume Blanchet
The obvious way to validate json is by mapping to a typed object through serialization (here with the most popular lib for that...
Read more >How to Use JSON Schema to Validate JSON Documents in ...
Python JSON Schema Definition In this post, we'll introduce how to use JSON Schema to validate JSON documents. We'll cover the essential ...
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
.Net Core team actively works on new JSON API implementation to replace Json.Net. All new features will be in .Net Core. Open feature request issues in CoreFX repo if you want more features - we will get them.
For reference #18023