Return Valid JSON for empty data
For commands that ask for JSON results, if the input to the Go JSON marshaller is empty, it will return a byte array with a literal "null" in it. If that is the case, we should output [] instead as at least that is valid JSON and will not break consumers of the data. Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
parent
3363064622
commit
3907e0d346
2 changed files with 14 additions and 1 deletions
|
@ -398,7 +398,9 @@ func getJSONOutput(containers []*libkpod.ContainerData, nSpace bool) (psOutput [
|
|||
|
||||
func generatePsOutput(containers []*libkpod.ContainerData, server *libkpod.ContainerServer, opts psOptions) error {
|
||||
containersOutput := getContainers(containers, opts)
|
||||
if len(containersOutput) == 0 {
|
||||
// In the case of JSON, we want to continue so we at least pass
|
||||
// {} --valid JSON-- to the consumer
|
||||
if len(containersOutput) == 0 && opts.format != formats.JSONString {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue