Skip to content
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

JSON formatting #163

Closed
estahn opened this issue Jun 14, 2017 · 5 comments
Closed

JSON formatting #163

estahn opened this issue Jun 14, 2017 · 5 comments

Comments

@estahn
Copy link

estahn commented Jun 14, 2017

The following will not pass YAML lint at the moment:

foo:
  bar: {{ `["foo", "bar"]` | json | toJSON }}

Expected Result:

foo:
  bar: ["foo", "bar"]

Actual Result:

foo:
  bar: ["foo","bar"]
@hairyhenderson
Copy link
Owner

I'm not sure what the issue is here - your listed "Actual" is valid YAML.

@estahn
Copy link
Author

estahn commented Jun 14, 2017

Yes, it's valid YAML according to the standard. We use YAML lint to check outputs and it complaints about the whitespace not existing:

http://yamllint.readthedocs.io/en/latest/rules.html#module-yamllint.rules.commas

@hairyhenderson
Copy link
Owner

Ok, I see. The purpose of the toJSON function is to marshal as JSON, and more specifically, as compact JSON (i.e. without any separating whitespace). The other option is to use toJSONPretty, but it would render the array across multiple lines:

$ gomplate -i '{{ `["foo", "bar"]` | jsonArray | toJSONPretty "  " }}'
[
  "foo",
  "bar"
]

Other than that, gomplate simply isn't going to produce YAML that satisfies your particular linter.

@estahn
Copy link
Author

estahn commented Jun 14, 2017

@hairyhenderson Fair enough, although the linter it's neither mine nor particular :)

@estahn estahn closed this as completed Jun 14, 2017
@hairyhenderson
Copy link
Owner

Ok, then instead of "your particular linter" read "the linter you're choosing to use, with its particular configuration" 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants