-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Breaking Change: JSONC no longer works after 7.4.0 #20782
Comments
It's likely the switch to System.Text.Json that has caused this: #18141 |
Unlike XML, JSON does not have a representation for comments, see The JavaScript Object Notation (JSON) Data Interchange Format. What you have there is some JSON with a C++ style comment which is not part of the specification. There are hundreds of JSON parsers and the only thing they have in common is the JSON specification. When you exchange JSON between different systems you risk parser failures if you don't stick to the spec. |
README |
@kyle-ntx, this selective switch to the Specifically, the latter supports:
Thus, there is now a blatant discrepancy between what # All of these *succeed* with ConvertFrom-Json, but *fail* with Test-Json
@(
'{ foo: "bar" }'
"{ foo: 'bar' }"
"{ foo: 'bar', }"
"{ foo:
'bar' // bar it is
}"
"{ foo: /* et
tu? */
'bar'
}"
) | Convertfrom-Json |
While being lenient may sound helpful, in the words of The Fat Controller, it causes confusion and delay. When passing JSON from one system to another you have no control over the other systems parser and should stick to the strict JSON specification. If you don't then you are basically passing garbage between one system and another and cannot trust any parser to interpret the data as you intended and may silently ignore some fields and accept others. |
|
Case in point: The "{'name': 'Ashley', 'age': 25}" | Test-Json |
How to allow some kinds of invalid JSON with System.Text.Json An example they give is
So worth running the current failures through that to find the best set of options represent the original behaviour. |
@rhubarb-geek-nz, from what I can tell, the |
You might have to bite the bullet and have the ConvertFrom-Json Cmdlet supporting both parsers, where a switch selects which one to use. |
While this is true, it does appear that JSON with Comments worked before, and does not now, and the introduction of this change has broken scripts which we have relied on for quite some time. I do agree that supporting things that are not part of a standard is fraught with danger, however, introducing a breaking change as part of a minor update and with out warning is not common practice and, if done at all, should be done with some forewarning and in the form of a major version change. |
Looks like this can be fixed pretty easily, |
@IISResetMe: As noted, this isn't sufficient: what That is, it won't be able to validate something I think what is called for is:
|
Sorry for the lazy comment above @mklement0, I was solely referring to the comment parsing issue with The following should evaluate without error with the suggested fix:
... but obviously won't resolve the bareword/single-quote property name issue. Fully agree on backwards compat. |
@PowerShell/wg-powershell-cmdlets reviewed this. System.Text.Json.Node allows for options that would allow for comments. We believe that the default behavior should adhere to the standards (enabling portable JSON), but have a new |
@SteveL-MSFT, the proposed fix:
Update: Just saw the following summary: |
Prerequisites
Steps to reproduce
Include a comment in json, one example can be seen here:
In previous versions of PS this worked as expected.
Expected behavior
Actual behavior
Error details
Environment data
Visuals
The text was updated successfully, but these errors were encountered: