jsonnet icon indicating copy to clipboard operation
jsonnet copied to clipboard

"eval" JSON manifestation indentation should match "fmt" default (3 v. 2)

Open seh opened this issue 7 years ago • 3 comments

When running the eval subcommand and manifesting JSON, jsonnet eval uses three spaces for its indentation step, per the manifestJSON function in file core/vm.cpp (specifically, here for arrays and here for objects). By contrast, the fmt uses two spaces for its default indentation step.

Why do these two subcommands differ in their indentation? It wouldn't matter as much if either they matched, or the indentation used by the eval subcommand was configurable via command-line flag. I'd prefer that they matched at two spaces per step.

seh avatar Jul 30 '18 15:07 seh

It took until later in the evening to realize that I'm complaining about the formatting of two different things here: how jsonnet eval emits JSON and how jsonnet fmt emits Jsonnet. Granted, the former is a subset of the latter, but that they are different things is arguably Jsonnet's raison d'être.

Still, I wonder whether this difference is indentation is deliberate. I'd like to emit JSON indented by two spaces. The std.manifestJsonEx function allows me to specify the indentation I desire, but my Jsonnet files don't use such a function explicitly today.

seh avatar Jul 31 '18 12:07 seh

I honestly can't remember why I chose 3 spaces but it's been there since the beginning. I wonder how disruptive it would be to change this? People who check generated JSON into version control would see huge patches obscuring changes. It could certainly be configurable. In particular, it might be nice to allow printing no-whitespace-at-all JSON for certain use cases.

sparkprime avatar Aug 07 '18 18:08 sparkprime

I pipe jsonnet output to jq so that indentation spaces to be 2 spaces.

Like this,

$ jsonnet tmp.jsonnet | jq

machisuke avatar Sep 12 '21 03:09 machisuke