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

Feature Request: Pretty-print option for JSONEncodeFunc #104

Closed
nl-brett-stime opened this issue Apr 29, 2021 · 1 comment
Closed

Feature Request: Pretty-print option for JSONEncodeFunc #104

nl-brett-stime opened this issue Apr 29, 2021 · 1 comment

Comments

@nl-brett-stime
Copy link

E.g.,

JSONEncode(someVal)

// Produces e.g.,
// {a:1,b:2,c:3}
indentSize := 4
JSONEncode(someVal, indentSize)

// Produces e.g.,
// {
//     a: 1,
//     b: 2,
//     c: 3
// }
@apparentlymart
Copy link
Collaborator

Hi @nl-brett-stime,

I intended this function primarily to help with integration with other software rather than for generating content intended for humans to interact with, and so it's intentionally not customizable. cty functions don't typically have optional arguments, because the model for functions doesn't support that idea, so I think it would be tricky to implement exactly the design you've proposed here even if not for my preference to exclude it.

I see you've also opened an issue in Terraform. The Terraform team might have a different opinion about what use-cases the Terraform language in particular is aiming to meet; if they conclude that such a thing would be in Terraform's scope then I'd suggest for Terraform to include a separate JSON formatting function which takes valid JSON as input and returns pretty-printed but functionally-equivalent JSON as output, which would then result with something like jsonformat(jsonencode(...)) in Terraform language terms (using Terraform/HCL's function syntax).

I don't really want to maintain a formatting function like that within this library because the function package is already pretty large as it is, but applications like Terraform would be able to define their own separate formatting functions if they wish, which could then consume the output of jsonencode or indeed JSON data obtained via other means.

Thanks!

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