diff --git a/collector/collector.go b/collector/collector.go index 40b4594..f36f2d1 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -489,9 +489,9 @@ func (c Config) Query(s string) (res string, err error) { if err := json.Unmarshal(b, &dat); err != nil { panic(err) } - // Adding "// empty" to the query so the output does not include a "null" if the value is empty + // Adding some jq options to the query so the output does not include "null" if the value is empty // This is not a json parse feature but a string one, so we should return normal values not json specific ones - query, err := gojq.Parse(s + "// empty") + query, err := gojq.Parse(s + " | if ( . | type) == \"null\" then empty else . end") if err != nil { return res, err } diff --git a/collector/collector_test.go b/collector/collector_test.go index 9dbe9fd..ec26f13 100644 --- a/collector/collector_test.go +++ b/collector/collector_test.go @@ -1095,6 +1095,7 @@ name: Mario err = os.WriteFile(path.Join(tmpDir, "local_config.yaml"), []byte(`#cloud-config local_key_1: local_value_1 +local_key_2: false some: other: key: 3 @@ -1126,6 +1127,9 @@ some: Expect(err).ToNot(HaveOccurred()) Expect(v).To(Equal("3\n")) Expect(c.Query("options")).To(Equal("foo: bar\n")) + v, err = c.Query("local_key_2") + Expect(err).ToNot(HaveOccurred()) + Expect(v).To(Equal("false\n")) }) }) })