colorjson
colorjson copied to clipboard
marshalValue silently fails for unsupported values
marshalValue
doesn't handle the wide range of values supported by encoding/json
(such as any value implementing json.Marshaler
) but silently fails (no output) instead of reporting an error indicating an unsupported data type.
Example: https://play.golang.org/p/dmF0aGDl0J5
package main
import (
"encoding/json"
"fmt"
"log"
"github.com/TylerBrock/colorjson"
)
func main() {
raw := json.RawMessage(`{
"str": "foo",
"num": 100,
"bool": false,
"null": null,
"array": ["foo", "bar", "baz"],
"obj": { "a": 1, "b": 2 }
}`)
f := colorjson.NewFormatter()
f.Indent = 2
b, err := f.Marshal(raw)
if err != nil {
log.Fatal(err)
}
if len(b) == 0 {
log.Fatal("no output")
}
fmt.Println(string(b))
}
Came across the same issue. When calling colorjson.Marshal no error and no output is returned back.
bump
same
same