-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow "jsonify" to pretty print JSON #5339
Conversation
tpl/encoding/encoding.go
Outdated
indentSpacing = " " | ||
} | ||
|
||
b, err := json.MarshalIndent(v, "", indentSpacing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting some very weird behaviour here - when I switched to json.MarshalIndent
and updated the respective table test, there was a panic occurring. I was looking into the docs for template.HTML
but everything looked ok at first glance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Respective logs from Travis: https://travis-ci.org/gohugoio/hugo/jobs/444259677#L759
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently running on go version go1.11.1 darwin/amd64 if that helps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: template.HTML("[\n \"a\",\n \"b\"\n]")
was the answer - I had to escape quotes
Small snippet for how package main
import (
"encoding/json"
"fmt"
"log"
)
func main() {
data := []string{"A", "B", "C"}
json, err := json.MarshalIndent(data, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Println(string(json))
} prints:
|
Thanks for this, and a special thanks for keeping the commit message in line ... so I could just click the button |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Fixes #5040: Allow "jsonify" to pretty print JSON
This PR replaces
json.Marshal
withjson.MarshalIndent
, to return pretty-printed output instead of compact. A sensible spacing of two spaces has chosen for the indentation.