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
new behaviour since v4.32.1: input json produces output json by default instead of yaml #1608
Comments
I'm wondering if it's related to #1582 |
testing in verbose mode, I understood the issue: the file is auto-detected as JSON, which somehow also set the output format to JSON - instead of the expected YAML. which explains the quotes. so not related to unwrapScalar, but rather to a wrong auto-detected output format. unless it is now expected that a JSON input produces JSON output... $ yq -v '.version' test.json
14:09:21 processArgs [DEBU] processed args: [.version test.json]
14:09:21 maybeFile [DEBU] checking '.version' is a file
14:09:21 maybeFile [DEBU] error: stat .version: no such file or directory
14:09:21 maybeFile [DEBU] result: false
14:09:21 processArgs [DEBU] assuming expression is '.version'
14:09:21 FormatFromFilename [DEBU] checking file extension 'test.json' for auto format detection
14:09:21 FormatFromFilename [DEBU] detected format 'json'
14:09:21 FormatFromFilename [DEBU] checking file extension 'test.json' for auto format detection
14:09:21 FormatFromFilename [DEBU] detected format 'json'
14:09:21 initCommand [DEBU] Using outputformat json
14:09:21 ParseExpression [DEBU] Parsing expression: [.version]
14:09:21 func1 [DEBU] PathToken version
14:09:21 handleToken [DEBU] processing version (55)
14:09:21 handleToken [DEBU] adding token to the fixed list
14:09:21 ConvertToPostfix [DEBU] postfix processing currentToken version (55)
14:09:21 ConvertToPostfix [DEBU] put version (55) onto the opstack
14:09:21 ConvertToPostfix [DEBU] postfix processing currentToken )
14:09:21 popOpToResult [DEBU] popped version (55) from opstack to results
14:09:21 ConvertToPostfix [DEBU] opstackLen: 0
14:09:21 ConvertToPostfix [DEBU] PostFix Result:
14:09:21 ConvertToPostfix [DEBU] > version
14:09:21 createExpressionTree [DEBU] pathTree version
14:09:21 Decode [DEBU] going to decode
14:09:21 GetMatchingNodes [DEBU] Processing Op: version
14:09:21 GetMatchingNodes [DEBU] D0, P[], (doc)::version: 1.2.3
14:09:21 GetMatchingNodes [DEBU] >>
14:09:21 traversePathOperator [DEBU] -- traversePathOperator
14:09:21 traverse [DEBU] Traversing D0, P[], (doc)::version: 1.2.3
14:09:21 traverse [DEBU] digging into doc node
14:09:21 traverse [DEBU] Traversing D0, P[], (!!map)::version: 1.2.3
14:09:21 traverse [DEBU] its a map with 1 entries
14:09:21 doTraverseMap [DEBU] checking version (!!str)
14:09:21 matchKey [DEBU] pattern: version
14:09:21 doTraverseMap [DEBU] MATCHED
14:09:21 doTraverseMap [DEBU] including value
14:09:21 PrintResults [DEBU] PrintResults for 1 matches
14:09:21 GetMatchingNodes [DEBU] Processing Op: EXPLODE
14:09:21 GetMatchingNodes [DEBU] D0, P[version], (!!str)::1.2.3
14:09:21 GetMatchingNodes [DEBU] >>
14:09:21 explodeOperator [DEBU] -- ExplodeOperation
14:09:21 GetMatchingNodes [DEBU] getMatchingNodes - nothing to do
14:09:21 PrintResults [DEBU] -- print sep logic: p.firstTimePrinting: false, previousDocIndex: 0, mappedDoc.Document: 0
14:09:21 PrintResults [DEBU] D0, P[version], (!!str)::1.2.3
"1.2.3"
14:09:21 PrintResults [DEBU] done printing results
14:09:21 Decode [DEBU] going to decode |
I have an additional issue with it not handling the file's extension. Previous this worked and outputted the content in yaml: Now I get this error:
I renamed my input file to Executed The work around was to force the output format: |
@vbehar yeah the intention is if you give it a JSON file it produces JSON output (and same for other formats) unless explicitly specified. I didn't think it would break existing behaviours, mainly because I had XML/CSV/etc in my head, and for those you previously had to specify the input format so this wouldn't affect them 🤔 Still I think it makes sense JSON => JSON by default. @MrMarkW I think that's a bug in the new behaviour, and should be a separate issue so I can resolve it separately to this - if it doesn't recognise the extension I should just make it default to yaml. I'll fix that ASAP. |
Though JSON => JSON makes lots of sense, personally I like it as well, on the other hand it's also a breaking change since yq had been always using yaml as the default output format. And that's something the users have get used to, so Hyrum's Law applies here. @mikefarah maybe the default output format change should be enabled only in next major version like yq v5? Just my 2 cents. |
Yeah it's a fair point - happy to reverse it if more people think it should.... |
As a YAML tool, I feed it filenames of all sort, that are YAML. It feels awkward to have to specify
I can certainly still
On the plus side, you have clearly made a fantastic tool that we use every day! And thanks for that! In the case of an extension that is not on the list above, just default to YAML and process away, it is then the user responsibility to feed it YAML... |
I've just made an update to default to yaml for unknown file extensions (v4.32.2) sorry about that! @cmaahs |
I just read #1582, and it looks like that was the intent :) These things happen... |
I did get a chuckle out of |
Hi I agreed both that parsing json should logically output json but also that yq is a yaml tool so output yaml by default (w'ont help you to choose ^^) |
I do also experience the same issue with output being json formatted since v4.32.1. explicitly adding -o=yaml fixed it for me :) |
I've updated 4.33.1 to log a warning for this issue:
|
this doesn't really seem like a sufficient fix. 4.32.1 -> 4.33.1 is just a minor release and should remain backwards compatible but it has breaking changes we use YQ across a lot of projects within github actions for version control and every one of them broke underneath us ( yes we should be using a fixed version and it is our fault too ) |
Yeah I'm really sorry about that - at the time I released it I didn't realise it was a breaking change :/ - and wouldn't have released it if I did. I'm reluctant to go back now - as it's been out in the wild for a couple of weeks and that could cause the same compatibility issues you are mentioning, but in reverse :S I think going forward, it makes sense to product JSON output when it gets JSON input - but I am sorry about unintentionally causing you to do a pile of work from the breaking change :( |
Bitten by this last week in my own release script, just found out 😂 |
Can I mention another subtle reason why this new behaviour isn't ideal? I have a script that runs in a GitHub action to test about of inputs and outputs, some JSON, some YAML. The new behaviour didn't break the script (because it uses
Then when I try to suppress the warnings in the script by putting So there doesn't seem to be a way to have it work with clean output across both versions. Thanks for your consideration!! |
This was really unfortunate change of behaviour, broke a lot of scripting in unpredictable way for my project. |
Describe the bug
since https://github.com/mikefarah/yq/releases/tag/v4.32.1 and more specifically #1582 a JSON input file is now auto-detected as JSON - instead of the previous YAML default format.
which implies that the output is automatically set to JSON format - instead of being YAML previously (= in the previous versions)
the impact is that for a single output value, the result is now wrapped in quotes.
Version of yq: 4.32.1
Operating system: mac and linux
Installed via: binary release and homebrew
Input JSON
data.json:
Command
The command you ran:
Actual behavior
Expected behavior
(which was the actual behaviour in v4.31.2 and older versions)
Additional context
yq -oy '.version' test.json
The text was updated successfully, but these errors were encountered: