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 #5040

Open
hach-que opened this Issue Aug 6, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@hach-que

hach-que commented Aug 6, 2018

"jsonify" currently uses json.Marshal which emits compact JSON.

We'd like to have the JSON output pretty printed (we're using Hugo for API documentation), so we need some function in Hugo that exposes json.MarshalIndent.

@bep

This comment has been minimized.

Member

bep commented Aug 6, 2018

I'm tempted to change the existing one to use json.MarshalIndent by default with a sensible indentation (2 spaces?) as default.

I assume we could also add a second optional argument for indentation:

{{ (slice "A" "B" "C") | jsonify "   " }}

@bep bep added the Enhancement label Aug 6, 2018

@bep bep modified the milestones: v0.47, v0.48 Aug 6, 2018

@bep bep modified the milestones: v0.48, v0.49 Aug 22, 2018

@bep bep modified the milestones: v0.49, v0.50 Sep 13, 2018

@bep bep modified the milestones: v0.50, v0.51 Oct 6, 2018

@SeanPrashad

This comment has been minimized.

Contributor

SeanPrashad commented Oct 21, 2018

Hey guys! I'd love to land this new feature if that's ok 😬

@bep

This comment has been minimized.

Member

bep commented Nov 2, 2018

@SeanPrashad I had to reopen this. I suggest we add an optional second argument so both of the below will work:

{{ (slice "A" "B" "C") | jsonify }}
{{ (slice "A" "B" "C") | jsonify "   " }}

SeanPrashad added a commit to SeanPrashad/hugo that referenced this issue Nov 3, 2018

tpl: Add option to pretty print using Jsonify
As existing use cases for Jsonify require no formatting, we'll need to
make pretty printing optional.

Fixes gohugoio#5040

@SeanPrashad SeanPrashad referenced a pull request that will close this issue Nov 3, 2018

Open

[WIP] Allow "Jsonify" the option to pretty print JSON #5396

SeanPrashad added a commit to SeanPrashad/hugo that referenced this issue Nov 3, 2018

tpl: Add option to pretty print using Jsonify
As existing use cases for Jsonify require no formatting, we'll need to
make pretty printing optional.

Fixes gohugoio#5040

@bep bep modified the milestones: v0.51, v0.53 Nov 8, 2018

@bep bep modified the milestones: v0.53, v0.54 Dec 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment