question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ConvertFrom-Json and Test-Json accept non-compliant/non-standard JSON - no way to strictly validate JSON

See original GitHub issue

Summary 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:open
  • Created 4 years ago
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
iSazonovcommented, Sep 27, 2019

.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.

1reaction
iSazonovcommented, Sep 6, 2022

For reference #18023

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found