Skip to content

Conversation

jandubois
Copy link
Member

@jandubois jandubois commented Sep 12, 2025

Unlike the YAML encoder, the JSON encoder will encode empty structs even when they have the json:",omitempty" tag (it will only emit nil pointers to structs).

This commit repeatedly removes empty objects until the result no longer gets any shorter. It doesn't check for the omitempty tag, but we have that tag set on every struct.

Example: this removes "vmOpts":{"qemu":{},"vz":{"rosetta":{}}}.

@jandubois jandubois force-pushed the list-json branch 5 times, most recently from b392b94 to a1f452d Compare September 12, 2025 05:22
afbjorklund

This comment was marked as resolved.

Copy link
Member

@afbjorklund afbjorklund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it only changes the output format for TTY - then it should be OK

@afbjorklund afbjorklund dismissed their stale review September 12, 2025 05:54

Still works for users like lima-gui, so invalid

@jandubois
Copy link
Member Author

jandubois commented Sep 12, 2025

Ah, it only changes the output format for TTY - then it should be OK

The change to show pretty-printed JSON for TTY output only was already in #3998.

This PR is only removing empty objects from the JSON output to make it identical to the YAML output.

The good thing is we have tests now to make sure the output stays in JSON Lines format when written to a pipe or file.

@jandubois jandubois added this to the v2.0.0 milestone Sep 12, 2025
Unlike the YAML encoder, the JSON encoder will encode empty structs
even when they have the `json:",omitempty"` tag (it will only emit nil
pointers to structs).

This commit repeatedly removes empty objects until the result no
longer gets any shorter. It doesn't check for the omitempty tag, but
we have that tag set on every struct.

Example: this removes `"vmOpts":{"qemu":{},"vz":{"rosetta":{}}}`.

Signed-off-by: Jan Dubois <[email protected]>
Always put --format at the end of the command to make it easier
to spot the difference between the commands.

Signed-off-by: Jan Dubois <[email protected]>
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jandubois jandubois merged commit 117f536 into lima-vm:master Sep 18, 2025
88 of 90 checks passed
@jandubois jandubois deleted the list-json branch September 18, 2025 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants