add option to compact result json
luisdavim opened this issue · comments
Luis Davim commented
Hi, it would be cool to have a way to get the resulting json compacted.
Josh Baker commented
sjson is designed to make changes to the json as quickly as possible, which means it doesn't concern itself with reformatting the json.
I recommend the pretty
package.
package main
import (
"github.com/tidwall/pretty"
"github.com/tidwall/sjson"
)
func main() {
json := `{
"hello": "jello"
}`
json, _ = sjson.Set(json, "hello", "pudding")
json = string(pretty.Ugly([]byte(json)))
println(json)
}
// output: {"hello":"pudding"}
Or, the gjson @ugly
modifier.
package main
import (
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)
func main() {
json := `{
"hello": "jello"
}`
json, _ = sjson.Set(json, "hello", "pudding")
json = gjson.Get(json, "@ugly").Raw
println(json)
}
// output: {"hello":"pudding"}